@agoric/ertp 0.16.3-mainnet1B-dev-26244e8.0 → 0.16.3-orchestration-dev-096c4e8.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.
Files changed (48) hide show
  1. package/package.json +26 -18
  2. package/src/amountMath.js +57 -63
  3. package/src/amountStore.js +32 -0
  4. package/src/index.js +7 -0
  5. package/src/issuerKit.js +218 -74
  6. package/src/legacy-payment-helpers.js +23 -28
  7. package/src/mathHelpers/copyBagMathHelpers.js +2 -4
  8. package/src/mathHelpers/copySetMathHelpers.js +1 -3
  9. package/src/mathHelpers/natMathHelpers.js +6 -7
  10. package/src/payment.js +5 -8
  11. package/src/paymentLedger.js +84 -91
  12. package/src/purse.js +83 -24
  13. package/src/typeGuards.js +37 -43
  14. package/src/types-ambient.js +237 -314
  15. package/src/types.js +237 -314
  16. package/CHANGELOG.md +0 -759
  17. package/src/amountMath.d.ts +0 -53
  18. package/src/amountMath.d.ts.map +0 -1
  19. package/src/displayInfo.d.ts +0 -2
  20. package/src/displayInfo.d.ts.map +0 -1
  21. package/src/index.d.ts +0 -4
  22. package/src/index.d.ts.map +0 -1
  23. package/src/issuerKit.d.ts +0 -19
  24. package/src/issuerKit.d.ts.map +0 -1
  25. package/src/legacy-payment-helpers.d.ts +0 -5
  26. package/src/legacy-payment-helpers.d.ts.map +0 -1
  27. package/src/mathHelpers/copyBagMathHelpers.d.ts +0 -5
  28. package/src/mathHelpers/copyBagMathHelpers.d.ts.map +0 -1
  29. package/src/mathHelpers/copySetMathHelpers.d.ts +0 -5
  30. package/src/mathHelpers/copySetMathHelpers.d.ts.map +0 -1
  31. package/src/mathHelpers/natMathHelpers.d.ts +0 -14
  32. package/src/mathHelpers/natMathHelpers.d.ts.map +0 -1
  33. package/src/mathHelpers/setMathHelpers.d.ts +0 -6
  34. package/src/mathHelpers/setMathHelpers.d.ts.map +0 -1
  35. package/src/payment.d.ts +0 -3
  36. package/src/payment.d.ts.map +0 -1
  37. package/src/paymentLedger.d.ts +0 -3
  38. package/src/paymentLedger.d.ts.map +0 -1
  39. package/src/purse.d.ts +0 -13
  40. package/src/purse.d.ts.map +0 -1
  41. package/src/transientNotifier.d.ts +0 -5
  42. package/src/transientNotifier.d.ts.map +0 -1
  43. package/src/typeGuards.d.ts +0 -42
  44. package/src/typeGuards.d.ts.map +0 -1
  45. package/src/types-ambient.d.ts +0 -376
  46. package/src/types-ambient.d.ts.map +0 -1
  47. package/src/types.d.ts +0 -376
  48. package/src/types.d.ts.map +0 -1
package/src/types.js CHANGED
@@ -5,240 +5,166 @@ export {};
5
5
 
6
6
  /**
7
7
  * @template {AssetKind} [K=AssetKind]
8
- * @typedef {object} Amount
9
- * Amounts are descriptions of digital assets, answering the questions
10
- * "how much" and "of what kind". Amounts are values labeled with a brand.
11
- * AmountMath executes the logic of how amounts are changed when digital
12
- * assets are merged, separated, or otherwise manipulated. For
13
- * example, a deposit of 2 bucks into a purse that already has 3 bucks
14
- * gives a new purse balance of 5 bucks. An empty purse has 0 bucks. AmountMath
15
- * relies heavily on polymorphic MathHelpers, which manipulate the unbranded
16
- * portion.
17
- *
8
+ * @typedef {object} Amount Amounts are descriptions of digital assets,
9
+ * answering the questions "how much" and "of what kind". Amounts are values
10
+ * labeled with a brand. AmountMath executes the logic of how amounts are
11
+ * changed when digital assets are merged, separated, or otherwise
12
+ * manipulated. For example, a deposit of 2 bucks into a purse that already
13
+ * has 3 bucks gives a new purse balance of 5 bucks. An empty purse has 0
14
+ * bucks. AmountMath relies heavily on polymorphic MathHelpers, which
15
+ * manipulate the unbranded portion.
18
16
  * @property {Brand<K>} brand
19
17
  * @property {AssetValueForKind<K>} value
20
18
  */
21
19
 
22
20
  /**
23
- * @typedef {NatValue | SetValue | CopySet | CopyBag} AmountValue
24
- * An `AmountValue` describes a set or quantity of assets that can be owned or
25
- * shared.
26
- *
27
- * A fungible `AmountValue` uses a non-negative bigint to represent a quantity
28
- * of that many assets.
29
- *
30
- * A non-fungible `AmountValue` uses an array or CopySet of `Key`s to represent
31
- * a set of whatever asset each key represents. A `Key` is a passable value
32
- * that can be used as an element in a set (SetStore or CopySet) or as the
33
- * key in a map (MapStore or CopyMap).
34
- *
35
- * `SetValue` is for the deprecated set representation, using an array directly
36
- * to represent the array of its elements. `CopySet` is the proper
37
- * representation using a CopySet.
38
- *
39
- * A semi-fungible `CopyBag` is represented as a
40
- * `CopyBag` of `Key` objects. "Bag" is synonymous with MultiSet, where an
41
- * element of a bag can be present once or more times, i.e., some positive
42
- * bigint number of times, representing that quantity of the asset represented
43
- * by that key.
21
+ * @typedef {NatValue | SetValue | CopySet | import('@endo/patterns').CopyBag} AmountValue
22
+ * An `AmountValue` describes a set or quantity of assets that can be owned or
23
+ * shared.
24
+ *
25
+ * A fungible `AmountValue` uses a non-negative bigint to represent a quantity
26
+ * of that many assets.
27
+ *
28
+ * A non-fungible `AmountValue` uses an array or CopySet of `Key`s to represent
29
+ * a set of whatever asset each key represents. A `Key` is a passable value
30
+ * that can be used as an element in a set (SetStore or CopySet) or as the key
31
+ * in a map (MapStore or CopyMap).
32
+ *
33
+ * `SetValue` is for the deprecated set representation, using an array directly
34
+ * to represent the array of its elements. `CopySet` is the proper
35
+ * representation using a CopySet.
36
+ *
37
+ * A semi-fungible `CopyBag` is represented as a `CopyBag` of `Key` objects.
38
+ * "Bag" is synonymous with MultiSet, where an element of a bag can be present
39
+ * once or more times, i.e., some positive bigint number of times,
40
+ * representing that quantity of the asset represented by that key.
44
41
  */
45
42
 
46
43
  /**
47
- * @typedef {'nat' | 'set' | 'copySet' | 'copyBag' } AssetKind
48
- *
49
- * See doc-comment for `AmountValue`.
44
+ * @typedef {'nat' | 'set' | 'copySet' | 'copyBag'} AssetKind See doc-comment
45
+ * for `AmountValue`.
50
46
  */
51
47
 
52
48
  /**
53
49
  * @template {AssetKind} K
54
- * @typedef {K extends 'nat' ? NatValue :
55
- * K extends 'set' ? SetValue :
56
- * K extends 'copySet' ? CopySet:
57
- * K extends 'copyBag' ? CopyBag :
58
- * never
59
- * } AssetValueForKind
50
+ * @typedef {K extends 'nat'
51
+ * ? NatValue
52
+ * : K extends 'set'
53
+ * ? SetValue
54
+ * : K extends 'copySet'
55
+ * ? CopySet
56
+ * : K extends 'copyBag'
57
+ * ? import('@endo/patterns').CopyBag
58
+ * : never} AssetValueForKind
60
59
  */
61
60
 
62
61
  /**
63
62
  * @template {AmountValue} V
64
- * @typedef {V extends NatValue ? 'nat' :
65
- * V extends SetValue ? 'set' :
66
- * V extends CopySet ? 'copySet' :
67
- * V extends CopyBag ? 'copyBag' :
68
- * never} AssetKindForValue
63
+ * @typedef {V extends NatValue
64
+ * ? 'nat'
65
+ * : V extends SetValue
66
+ * ? 'set'
67
+ * : V extends CopySet
68
+ * ? 'copySet'
69
+ * : V extends import('@endo/patterns').CopyBag
70
+ * ? 'copyBag'
71
+ * : never} AssetKindForValue
69
72
  */
70
73
 
71
74
  /**
72
75
  * @template {AssetKind} [K=AssetKind]
73
76
  * @typedef {object} DisplayInfo
74
- * @property {number} [decimalPlaces] Tells the display software how
75
- * many decimal places to move the decimal over to the left, or in
76
- * other words, which position corresponds to whole numbers. We
77
- * require fungible digital assets to be represented in integers, in
78
- * the smallest unit (i.e. USD might be represented in mill, a
79
- * thousandth of a dollar. In that case, `decimalPlaces` would be
80
- * 3.) This property is optional, and for non-fungible digital
81
- * assets, should not be specified. The decimalPlaces property
82
- * should be used for *display purposes only*. Any other use is an
77
+ * @property {number} [decimalPlaces] Tells the display software how many
78
+ * decimal places to move the decimal over to the left, or in other words,
79
+ * which position corresponds to whole numbers. We require fungible digital
80
+ * assets to be represented in integers, in the smallest unit (i.e. USD might
81
+ * be represented in mill, a thousandth of a dollar. In that case,
82
+ * `decimalPlaces` would be 3.) This property is optional, and for
83
+ * non-fungible digital assets, should not be specified. The decimalPlaces
84
+ * property should be used for _display purposes only_. Any other use is an
83
85
  * anti-pattern.
84
- * @property {K} assetKind - the kind of asset, either
85
- * AssetKind.NAT (fungible) or
86
- * AssetKind.SET or AssetKind.COPY_SET (non-fungible)
86
+ * @property {K} assetKind - the kind of asset, either AssetKind.NAT (fungible)
87
+ * or AssetKind.SET or AssetKind.COPY_SET (non-fungible)
87
88
  */
88
89
 
89
90
  /**
90
91
  * @template {AssetKind} [K=AssetKind]
91
- * @typedef {object} Brand
92
- * The brand identifies the kind of issuer, and has a function to get the
93
- * alleged name for the kind of asset described. The alleged name (such
94
- * as 'BTC' or 'moola') is provided by the maker of the issuer and should
95
- * not be trusted as accurate.
96
- *
97
- * Every amount created by a particular AmountMath will share the same brand,
98
- * but recipients cannot rely on the brand to verify that a purported amount
99
- * represents the issuer they intended, since the same brand can be reused by
100
- * a misbehaving issuer.
101
- *
92
+ * @typedef {object} Brand The brand identifies the kind of issuer, and has a
93
+ * function to get the alleged name for the kind of asset described. The
94
+ * alleged name (such as 'BTC' or 'moola') is provided by the maker of the
95
+ * issuer and should not be trusted as accurate.
96
+ *
97
+ * Every amount created by a particular AmountMath will share the same brand,
98
+ * but recipients cannot rely on the brand to verify that a purported amount
99
+ * represents the issuer they intended, since the same brand can be reused by
100
+ * a misbehaving issuer.
102
101
  * @property {(allegedIssuer: ERef<Issuer>) => Promise<boolean>} isMyIssuer
103
- * Should be used with `issuer.getBrand` to ensure an issuer and brand match.
102
+ * Should be used with `issuer.getBrand` to ensure an issuer and brand match.
104
103
  * @property {() => string} getAllegedName
105
- * @property {() => DisplayInfo<K>} getDisplayInfo
106
- * Give information to UI on how to display the amount.
104
+ * @property {() => DisplayInfo<K>} getDisplayInfo Give information to UI on how
105
+ * to display the amount.
107
106
  * @property {() => Pattern} getAmountShape
108
107
  */
109
108
 
110
109
  // /////////////////////////// Issuer //////////////////////////////////////////
111
110
 
112
111
  /**
113
- * @callback IssuerIsLive
114
- *
115
- * Return true if the payment continues to exist.
116
- *
117
- * If the payment is a promise, the operation will proceed upon
118
- * resolution.
112
+ * @callback IssuerIsLive Return true if the payment continues to exist.
119
113
  *
114
+ * If the payment is a promise, the operation will proceed upon fulfillment.
120
115
  * @param {ERef<Payment>} payment
121
116
  * @returns {Promise<boolean>}
122
117
  */
123
118
  /**
124
119
  * @template {AssetKind} K
125
- * @callback IssuerGetAmountOf
126
- *
127
- * Get the amount of digital assets in the payment. Because the
128
- * payment is not trusted, we cannot call a method on it directly, and
129
- * must use the issuer instead.
130
- *
131
- * If the payment is a promise, the operation will proceed upon
132
- * resolution.
120
+ * @callback IssuerGetAmountOf Get the amount of digital assets in the payment.
121
+ * Because the payment is not trusted, we cannot call a method on it directly,
122
+ * and must use the issuer instead.
133
123
  *
124
+ * If the payment is a promise, the operation will proceed upon fulfillment.
134
125
  * @param {ERef<Payment>} payment
135
126
  * @returns {Promise<Amount<K>>}
136
127
  */
137
128
 
138
129
  /**
139
- * @callback IssuerBurn
140
- *
141
- * Burn all of the digital assets in the
142
- * payment. `optAmount` is optional. If `optAmount` is present, the
143
- * code will insist that the amount of the digital assets in the
144
- * payment is equal to `optAmount`, to prevent sending the wrong
145
- * payment and other confusion.
146
- *
147
- * If the payment is a promise, the operation will proceed upon
148
- * resolution.
149
- *
130
+ * @callback IssuerBurn Burn all of the digital assets in the payment.
131
+ * `optAmountShape` is optional. If the `optAmountShape` pattern is present,
132
+ * the amount of the digital assets in the payment must match
133
+ * `optAmountShape`, to prevent sending the wrong payment and other
134
+ * confusion.
135
+ *
136
+ * If the payment is a promise, the operation will proceed upon fulfillment.
137
+ *
138
+ * As always with optional `Pattern` arguments, keep in mind that technically
139
+ * the value `undefined` itself is a valid `Key` and therefore a valid
140
+ * `Pattern`. But in optional pattern position, a top level `undefined` will
141
+ * be interpreted as absence. If you want to express a `Pattern` that will
142
+ * match only `undefined`, use `M.undefined()` instead.
150
143
  * @param {ERef<Payment>} payment
151
144
  * @param {Pattern} [optAmountShape]
152
145
  * @returns {Promise<Amount>}
153
146
  */
154
147
 
155
- /**
156
- * @template {AssetKind} K
157
- * @callback IssuerClaim
158
- *
159
- * Transfer all digital assets from the payment to a new payment and
160
- * delete the original. `optAmount` is optional. If `optAmount` is
161
- * present, the code will insist that the amount of digital assets in
162
- * the payment is equal to `optAmount`, to prevent sending the wrong
163
- * payment and other confusion.
164
- *
165
- * If the payment is a promise, the operation will proceed upon
166
- * resolution.
167
- *
168
- * @param {ERef<Payment<K>>} payment
169
- * @param {Pattern} [optAmountShape]
170
- * @returns {Promise<Payment<K>>}
171
- */
172
-
173
- /**
174
- * @template {AssetKind} K
175
- * @callback IssuerCombine
176
- *
177
- * Combine multiple payments into one payment.
178
- *
179
- * If any of the payments is a promise, the operation will proceed
180
- * upon resolution.
181
- *
182
- * @param {ERef<Payment<K>>[]} paymentsArray
183
- * @param {Amount<K>} [optTotalAmount]
184
- * @returns {Promise<Payment<K>>}
185
- */
186
-
187
- /**
188
- * @template {AssetKind} K
189
- * @callback IssuerSplit
190
- *
191
- * Split a single payment into two payments,
192
- * A and B, according to the paymentAmountA passed in.
193
- *
194
- * If the payment is a promise, the operation will proceed upon
195
- * resolution.
196
- *
197
- * @param {ERef<Payment<K>>} payment
198
- * @param {Amount<K>} paymentAmountA
199
- * @returns {Promise<Payment<K>[]>}
200
- */
201
-
202
- /**
203
- * @callback IssuerSplitMany
204
- *
205
- * Split a single payment into many payments, according to the amounts
206
- * passed in.
207
- *
208
- * If the payment is a promise, the operation will proceed upon
209
- * resolution.
210
- *
211
- * @param {ERef<Payment>} payment
212
- * @param {Amount[]} amounts
213
- * @returns {Promise<Payment[]>}
214
- */
215
-
216
148
  /**
217
149
  * @template {AssetKind} [K=AssetKind]
218
- * @typedef {object} Issuer
219
- *
220
- * The issuer cannot mint a new amount, but it can create empty purses
221
- * and payments. The issuer can also transform payments (splitting
222
- * payments, combining payments, burning payments, and claiming
223
- * payments exclusively). The issuer should be gotten from a trusted
224
- * source and then relied upon as the decider of whether an untrusted
225
- * payment is valid.
226
- *
227
- * @property {() => Brand<K>} getBrand Get the Brand for this Issuer. The
228
- * Brand indicates the type of digital asset and is shared by the
229
- * mint, the issuer, and any purses and payments of this particular
230
- * kind. The brand is not closely held, so this function should not be
231
- * trusted to identify an issuer alone. Fake digital assets and amount
232
- * can use another issuer's brand.
233
- *
234
- * @property {() => string} getAllegedName Get the allegedName for
235
- * this mint/issuer
236
- * @property {() => AssetKind} getAssetKind Get the kind of
237
- * MathHelpers used by this Issuer.
238
- * @property {() => DisplayInfo<K>} getDisplayInfo Give information to UI
239
- * on how to display amounts for this issuer.
240
- * @property {() => Purse<K>} makeEmptyPurse Make an empty purse of this
241
- * brand.
150
+ * @typedef {object} Issuer The issuer cannot mint a new amount, but it can
151
+ * create empty purses and payments. The issuer can also transform payments
152
+ * (splitting payments, combining payments, burning payments, and claiming
153
+ * payments exclusively). The issuer should be gotten from a trusted source
154
+ * and then relied upon as the decider of whether an untrusted payment is
155
+ * valid.
156
+ * @property {() => Brand<K>} getBrand Get the Brand for this Issuer. The Brand
157
+ * indicates the type of digital asset and is shared by the mint, the issuer,
158
+ * and any purses and payments of this particular kind. The brand is not
159
+ * closely held, so this function should not be trusted to identify an issuer
160
+ * alone. Fake digital assets and amount can use another issuer's brand.
161
+ * @property {() => string} getAllegedName Get the allegedName for this
162
+ * mint/issuer
163
+ * @property {() => AssetKind} getAssetKind Get the kind of MathHelpers used by
164
+ * this Issuer.
165
+ * @property {() => DisplayInfo<K>} getDisplayInfo Give information to UI on how
166
+ * to display amounts for this issuer.
167
+ * @property {() => Purse<K>} makeEmptyPurse Make an empty purse of this brand.
242
168
  * @property {IssuerIsLive} isLive
243
169
  * @property {IssuerGetAmountOf<K>} getAmountOf
244
170
  * @property {IssuerBurn} burn
@@ -248,7 +174,9 @@ export {};
248
174
  * @template {AssetKind} [K=AssetKind]
249
175
  * @typedef {object} PaymentLedger
250
176
  * @property {Mint<K>} mint
251
- * @property {Purse<K>} mintRecoveryPurse
177
+ * @property {Purse<K>} mintRecoveryPurse Externally useful only if this issuer
178
+ * uses recovery sets. Can be used to get the recovery set associated with
179
+ * minted payments that are still live.
252
180
  * @property {Issuer<K>} issuer
253
181
  * @property {Brand<K>} brand
254
182
  */
@@ -257,7 +185,9 @@ export {};
257
185
  * @template {AssetKind} [K=AssetKind]
258
186
  * @typedef {object} IssuerKit
259
187
  * @property {Mint<K>} mint
260
- * @property {Purse<K>} mintRecoveryPurse
188
+ * @property {Purse<K>} mintRecoveryPurse Externally useful only if this issuer
189
+ * uses recovery sets. Can be used to get the recovery set associated with
190
+ * minted payments that are still live.
261
191
  * @property {Issuer<K>} issuer
262
192
  * @property {Brand<K>} brand
263
193
  * @property {DisplayInfo} displayInfo
@@ -265,35 +195,49 @@ export {};
265
195
 
266
196
  /**
267
197
  * @typedef {object} AdditionalDisplayInfo
268
- *
269
- * @property {number} [decimalPlaces] Tells the display software how
270
- * many decimal places to move the decimal over to the left, or in
271
- * other words, which position corresponds to whole numbers. We
272
- * require fungible digital assets to be represented in integers, in
273
- * the smallest unit (i.e. USD might be represented in mill, a
274
- * thousandth of a dollar. In that case, `decimalPlaces` would be
275
- * 3.) This property is optional, and for non-fungible digital
276
- * assets, should not be specified. The decimalPlaces property
277
- * should be used for *display purposes only*. Any other use is an
198
+ * @property {number} [decimalPlaces] Tells the display software how many
199
+ * decimal places to move the decimal over to the left, or in other words,
200
+ * which position corresponds to whole numbers. We require fungible digital
201
+ * assets to be represented in integers, in the smallest unit (i.e. USD might
202
+ * be represented in mill, a thousandth of a dollar. In that case,
203
+ * `decimalPlaces` would be 3.) This property is optional, and for
204
+ * non-fungible digital assets, should not be specified. The decimalPlaces
205
+ * property should be used for _display purposes only_. Any other use is an
278
206
  * anti-pattern.
279
207
  * @property {AssetKind} [assetKind]
280
208
  */
281
209
 
282
- /**
283
- * @typedef {import('@agoric/swingset-vat').ShutdownWithFailure} ShutdownWithFailure
284
- */
210
+ /** @typedef {import('@agoric/swingset-vat').ShutdownWithFailure} ShutdownWithFailure */
285
211
 
286
212
  /**
287
213
  * @template {AssetKind} [K=AssetKind]
288
- * @typedef {object} Mint
289
- * Holding a Mint carries the right to issue new digital assets. These
290
- * assets all have the same kind, which is called a Brand.
291
- *
214
+ * @typedef {object} Mint Holding a Mint carries the right to issue new digital
215
+ * assets. These assets all have the same kind, which is called a Brand.
292
216
  * @property {() => Issuer<K>} getIssuer Gets the Issuer for this mint.
293
- * @property {(newAmount: Amount<K>) => Payment<K>} mintPayment
294
- * Creates a new Payment containing newly minted amount.
217
+ * @property {(newAmount: Amount<K>) => Payment<K>} mintPayment Creates a new
218
+ * Payment containing newly minted amount.
295
219
  */
296
220
 
221
+ // /////////////////////////// Purse / Payment /////////////////////////////////
222
+
223
+ /**
224
+ * Issuers first became durable with mandatory recovery sets. Later they were
225
+ * made optional, but there is no support for converting from one state to the
226
+ * other. Thus, absence of a `RecoverySetsOption` state is equivalent to
227
+ * `'hasRecoverySets'`. In the absence of a `recoverySetsOption` parameter,
228
+ * upgradeIssuerKit defaults to the predecessor's `RecoverySetsOption` state, or
229
+ * `'hasRecoverySets'` if none.
230
+ *
231
+ * At this time, issuers started in one of the states (`'noRecoverySets'`, or
232
+ * `'hasRecoverySets'`) cannot be converted to the other on upgrade. If this
233
+ * transition is needed, it can likely be supported in a future upgrade. File an
234
+ * issue on github and explain what you need and why.
235
+ *
236
+ * @typedef {'hasRecoverySets' | 'noRecoverySets'} RecoverySetsOption
237
+ */
238
+
239
+ // /////////////////////////// Purse / Payment /////////////////////////////////
240
+
297
241
  /**
298
242
  * @callback DepositFacetReceive
299
243
  * @param {Payment} payment
@@ -303,12 +247,12 @@ export {};
303
247
 
304
248
  /**
305
249
  * @typedef {object} DepositFacet
306
- * @property {DepositFacetReceive} receive
307
- * Deposit all the contents of payment into the purse that made this facet,
308
- * returning the amount. If the optional argument `optAmount` does not equal the
309
- * amount of digital assets in the payment, throw an error.
250
+ * @property {DepositFacetReceive} receive Deposit all the contents of payment
251
+ * into the purse that made this facet, returning the amount. If the optional
252
+ * argument `optAmount` does not equal the amount of digital assets in the
253
+ * payment, throw an error.
310
254
  *
311
- * If payment is a promise, throw an error.
255
+ * If payment is a promise, throw an error.
312
256
  */
313
257
 
314
258
  /**
@@ -321,121 +265,100 @@ export {};
321
265
 
322
266
  /**
323
267
  * @template {AssetKind} [K=AssetKind]
324
- * @typedef {object} Purse
325
- * Purses hold amount of digital assets of the same brand, but unlike Payments,
326
- * they are not meant to be sent to others. To transfer digital assets, a
327
- * Payment should be withdrawn from a Purse. The amount of digital
328
- * assets in a purse can change through the action of deposit() and withdraw().
329
- *
330
- * The primary use for Purses and Payments is for currency-like and goods-like
331
- * digital assets, but they can also be used to represent other kinds of rights,
332
- * such as the right to participate in a particular contract.
333
- *
334
- * @property {() => Brand<K>} getAllegedBrand Get the alleged Brand for this Purse
335
- *
336
- * @property {() => Amount<K>} getCurrentAmount
337
- * Get the amount contained in this purse.
338
- *
339
- * @property {() => LatestTopic<Amount<K>>} getCurrentAmountNotifier
340
- * Get a lossy notifier for changes to this purse's balance.
341
- *
342
- * @property {PurseDeposit<K>} deposit
343
- * Deposit all the contents of payment into this purse, returning the
344
- * amount. If the optional argument `optAmount` does not equal the
345
- * amount of digital assets in the payment, throw an error.
346
- *
347
- * If payment is a promise, throw an error.
348
- *
349
- * @property {() => DepositFacet} getDepositFacet
350
- * Return an object whose `receive` method deposits to the current Purse.
351
- *
352
- * @property {(amount: Amount<K>) => Payment<K>} withdraw
353
- * Withdraw amount from this purse into a new Payment.
354
- *
355
- * @property {() => CopySet<Payment<K>>} getRecoverySet
356
- * The set of payments withdrawn from this purse that are still live. These
357
- * are the payments that can still be recovered in emergencies by, for example,
358
- * depositing into this purse. Such a deposit action is like canceling an
359
- * outstanding check because you're tired of waiting for it. Once your
360
- * cancellation is acknowledged, you can spend the assets at stake on other
361
- * things. Afterwards, if the recipient of the original check finally gets
362
- * around to depositing it, their deposit fails.
363
- *
364
- * @property {() => Amount<K>} recoverAll
365
- * For use in emergencies, such as coming back from a traumatic crash and
366
- * upgrade. This deposits all the payments in this purse's recovery set
367
- * into the purse itself, returning the total amount of assets recovered.
268
+ * @typedef {object} Purse Purses hold amount of digital assets of the same
269
+ * brand, but unlike Payments, they are not meant to be sent to others. To
270
+ * transfer digital assets, a Payment should be withdrawn from a Purse. The
271
+ * amount of digital assets in a purse can change through the action of
272
+ * deposit() and withdraw().
273
+ *
274
+ * The primary use for Purses and Payments is for currency-like and goods-like
275
+ * digital assets, but they can also be used to represent other kinds of
276
+ * rights, such as the right to participate in a particular contract.
277
+ * @property {() => Brand<K>} getAllegedBrand Get the alleged Brand for this
278
+ * Purse
279
+ * @property {() => Amount<K>} getCurrentAmount Get the amount contained in this
280
+ * purse.
281
+ * @property {() => LatestTopic<Amount<K>>} getCurrentAmountNotifier Get a lossy
282
+ * notifier for changes to this purse's balance.
283
+ * @property {PurseDeposit<K>} deposit Deposit all the contents of payment into
284
+ * this purse, returning the amount. If the optional argument `optAmount` does
285
+ * not equal the amount of digital assets in the payment, throw an error.
286
+ *
287
+ * If payment is a promise, throw an error.
288
+ * @property {() => DepositFacet} getDepositFacet Return an object whose
289
+ * `receive` method deposits to the current Purse.
290
+ * @property {(amount: Amount<K>) => Payment<K>} withdraw Withdraw amount from
291
+ * this purse into a new Payment.
292
+ * @property {() => CopySet<Payment<K>>} getRecoverySet The set of payments
293
+ * withdrawn from this purse that are still live. These are the payments that
294
+ * can still be recovered in emergencies by, for example, depositing into this
295
+ * purse. Such a deposit action is like canceling an outstanding check because
296
+ * you're tired of waiting for it. Once your cancellation is acknowledged, you
297
+ * can spend the assets at stake on other things. Afterwards, if the recipient
298
+ * of the original check finally gets around to depositing it, their deposit
299
+ * fails.
300
+ *
301
+ * Returns an empty set if this issuer does not support recovery sets.
302
+ * @property {() => Amount<K>} recoverAll For use in emergencies, such as coming
303
+ * back from a traumatic crash and upgrade. This deposits all the payments in
304
+ * this purse's recovery set into the purse itself, returning the total amount
305
+ * of assets recovered.
306
+ *
307
+ * Returns an empty amount if this issuer does not support recovery sets.
368
308
  */
369
309
 
370
310
  /**
371
311
  * @template {AssetKind} [K=AssetKind]
372
- * @typedef {object} Payment
373
- * Payments hold amount of digital assets of the same brand in transit. Payments
374
- * can be deposited in purses, split into multiple payments, combined, and
375
- * claimed (getting an exclusive payment). Payments are linear, meaning
376
- * that either a payment has the same amount of digital assets it
377
- * started with, or it is used up entirely. It is impossible to partially use a
378
- * payment.
379
- *
380
- * Payments are often received from other actors and therefore should
381
- * not be trusted themselves. To get the amount of digital assets in a payment,
382
- * use the trusted issuer: issuer.getAmountOf(payment),
383
- *
384
- * Payments can be converted to Purses by getting a trusted issuer and
385
- * calling `issuer.makeEmptyPurse()` to create a purse, then
386
- * `purse.deposit(payment)`.
387
- *
388
- * @property {() => Brand<K>} getAllegedBrand
389
- * Get the allegedBrand, indicating the type of digital asset this
390
- * payment purports to be, and which issuer to use. Because payments
391
- * are not trusted, any method calls on payments should be treated
392
- * with suspicion and verified elsewhere.
312
+ * @typedef {object} Payment Payments hold amount of digital assets of the same
313
+ * brand in transit. Payments can be deposited in purses, split into multiple
314
+ * payments, combined, and claimed (getting an exclusive payment). Payments
315
+ * are linear, meaning that either a payment has the same amount of digital
316
+ * assets it started with, or it is used up entirely. It is impossible to
317
+ * partially use a payment.
318
+ *
319
+ * Payments are often received from other actors and therefore should not be
320
+ * trusted themselves. To get the amount of digital assets in a payment, use
321
+ * the trusted issuer: issuer.getAmountOf(payment),
322
+ *
323
+ * Payments can be converted to Purses by getting a trusted issuer and calling
324
+ * `issuer.makeEmptyPurse()` to create a purse, then
325
+ * `purse.deposit(payment)`.
326
+ * @property {() => Brand<K>} getAllegedBrand Get the allegedBrand, indicating
327
+ * the type of digital asset this payment purports to be, and which issuer to
328
+ * use. Because payments are not trusted, any method calls on payments should
329
+ * be treated with suspicion and verified elsewhere.
393
330
  */
394
331
 
332
+ // /////////////////////////// MathHelpers /////////////////////////////////////
333
+
395
334
  /**
396
335
  * @template {AmountValue} V
397
- * @typedef {object} MathHelpers
398
- * All of the difference in how digital asset amount are manipulated can be
399
- * reduced to the behavior of the math on values. We extract this
400
- * custom logic into mathHelpers. MathHelpers are about value
401
- * arithmetic, whereas AmountMath is about amounts, which are the
402
- * values labeled with a brand. AmountMath use mathHelpers to do their value
403
- * arithmetic, and then brand the results, making a new amount.
404
- *
405
- * The MathHelpers are designed to be called only from AmountMath, and so
406
- * all methods but coerce can assume their inputs are valid. They only
407
- * need to do output validation, and only when there is a possibility of
408
- * invalid output.
409
- *
410
- * @property {(allegedValue: V) => V} doCoerce
411
- * Check the kind of this value and throw if it is not the
412
- * expected kind.
413
- *
414
- * @property {() => V} doMakeEmpty
415
- * Get the representation for the identity element (often 0 or an
416
- * empty array)
417
- *
418
- * @property {(value: V) => boolean} doIsEmpty
419
- * Is the value the identity element?
420
- *
421
- * @property {(left: V, right: V) => boolean} doIsGTE
422
- * Is the left greater than or equal to the right?
423
- *
424
- * @property {(left: V, right: V) => boolean} doIsEqual
425
- * Does left equal right?
426
- *
427
- * @property {(left: V, right: V) => V} doAdd
428
- * Return the left combined with the right.
429
- *
430
- * @property {(left: V, right: V) => V} doSubtract
431
- * Return what remains after removing the right from the left. If
432
- * something in the right was not in the left, we throw an error.
336
+ * @typedef {object} MathHelpers All of the difference in how digital asset
337
+ * amount are manipulated can be reduced to the behavior of the math on
338
+ * values. We extract this custom logic into mathHelpers. MathHelpers are
339
+ * about value arithmetic, whereas AmountMath is about amounts, which are the
340
+ * values labeled with a brand. AmountMath use mathHelpers to do their value
341
+ * arithmetic, and then brand the results, making a new amount.
342
+ *
343
+ * The MathHelpers are designed to be called only from AmountMath, and so all
344
+ * methods but coerce can assume their inputs are valid. They only need to do
345
+ * output validation, and only when there is a possibility of invalid output.
346
+ * @property {(allegedValue: V) => V} doCoerce Check the kind of this value and
347
+ * throw if it is not the expected kind.
348
+ * @property {() => V} doMakeEmpty Get the representation for the identity
349
+ * element (often 0 or an empty array)
350
+ * @property {(value: V) => boolean} doIsEmpty Is the value the identity
351
+ * element?
352
+ * @property {(left: V, right: V) => boolean} doIsGTE Is the left greater than
353
+ * or equal to the right?
354
+ * @property {(left: V, right: V) => boolean} doIsEqual Does left equal right?
355
+ * @property {(left: V, right: V) => V} doAdd Return the left combined with the
356
+ * right.
357
+ * @property {(left: V, right: V) => V} doSubtract Return what remains after
358
+ * removing the right from the left. If something in the right was not in the
359
+ * left, we throw an error.
433
360
  */
434
361
 
435
- /**
436
- * @typedef {bigint} NatValue
437
- */
362
+ /** @typedef {bigint} NatValue */
438
363
 
439
- /**
440
- * @typedef {Array<Key>} SetValue
441
- */
364
+ /** @typedef {Key[]} SetValue */