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