@agoric/ertp 0.16.3-dev-727e4af.0 → 0.16.3-dev-96c9ff5.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.
- package/package.json +16 -16
- package/src/amountMath.d.ts +20 -16
- package/src/amountMath.d.ts.map +1 -1
- package/src/amountMath.js +68 -54
- package/src/issuerKit.d.ts +1 -1
- package/src/issuerKit.d.ts.map +1 -1
- package/src/issuerKit.js +1 -1
- package/src/legacy-payment-helpers.d.ts +3 -3
- package/src/legacy-payment-helpers.d.ts.map +1 -1
- package/src/legacy-payment-helpers.js +5 -4
- package/src/mathHelpers/copyBagMathHelpers.d.ts +1 -1
- package/src/mathHelpers/copyBagMathHelpers.d.ts.map +1 -1
- package/src/paymentLedger.d.ts.map +1 -1
- package/src/paymentLedger.js +4 -20
- package/src/purse.d.ts +3 -4
- package/src/purse.d.ts.map +1 -1
- package/src/types.d.ts +121 -94
- package/src/types.d.ts.map +1 -1
- package/src/types.js +132 -81
package/src/types.js
CHANGED
|
@@ -5,23 +5,45 @@ export {};
|
|
|
5
5
|
|
|
6
6
|
/// <reference types="ses"/>
|
|
7
7
|
/**
|
|
8
|
-
* @import {
|
|
9
|
-
* @import {CopySet, Key} from '@endo/patterns')
|
|
8
|
+
* @import {Passable, RemotableObject} from '@endo/pass-style')
|
|
9
|
+
* @import {CopyBag, CopySet, Key} from '@endo/patterns')
|
|
10
10
|
* @import {LatestTopic, NotifierRecord} from '@agoric/notifier');
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
/** @typedef {{ brand: Brand<'nat'>; value: bigint }} NatAmount */
|
|
14
|
+
/**
|
|
15
|
+
* @template {Key} K
|
|
16
|
+
* @typedef {{ brand: Brand<'set'>; value: K[] }} SetAmount
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* @template {Key} K
|
|
20
|
+
* @typedef {{ brand: Brand<'copySet'>; value: CopySet<K> }} CopySetAmount
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* @template {Key} K
|
|
24
|
+
* @typedef {{ brand: Brand<'copyBag'>; value: CopyBag<K> }} CopyBagAmount
|
|
25
|
+
*/
|
|
26
|
+
/** @typedef {{ brand: Brand<any>; value: any }} AnyAmount */
|
|
27
|
+
|
|
13
28
|
/**
|
|
14
29
|
* @template {AssetKind} [K=AssetKind]
|
|
15
|
-
* @
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
30
|
+
* @template {Key} [M=Key]
|
|
31
|
+
* @typedef {K extends 'nat'
|
|
32
|
+
* ? NatAmount
|
|
33
|
+
* : K extends 'set'
|
|
34
|
+
* ? SetAmount<M>
|
|
35
|
+
* : K extends 'copySet'
|
|
36
|
+
* ? CopySetAmount<M>
|
|
37
|
+
* : K extends 'copyBag'
|
|
38
|
+
* ? CopyBagAmount<M>
|
|
39
|
+
* : AnyAmount} Amount
|
|
40
|
+
* Amounts are descriptions of digital assets, answering the questions "how
|
|
41
|
+
* much" and "of what kind". Amounts are values labeled with a brand.
|
|
42
|
+
* AmountMath executes the logic of how amounts are changed when digital
|
|
43
|
+
* assets are merged, separated, or otherwise manipulated. For example, a
|
|
44
|
+
* deposit of 2 bucks into a purse that already has 3 bucks gives a new purse
|
|
45
|
+
* balance of 5 bucks. An empty purse has 0 bucks. AmountMath relies heavily
|
|
46
|
+
* on polymorphic MathHelpers, which manipulate the unbranded portion.
|
|
25
47
|
*/
|
|
26
48
|
|
|
27
49
|
/**
|
|
@@ -54,14 +76,15 @@ export {};
|
|
|
54
76
|
|
|
55
77
|
/**
|
|
56
78
|
* @template {AssetKind} K
|
|
79
|
+
* @template {Key} [M=Key] member kind, for Amounts that have member values
|
|
57
80
|
* @typedef {K extends 'nat'
|
|
58
81
|
* ? NatValue
|
|
59
82
|
* : K extends 'set'
|
|
60
|
-
* ? SetValue
|
|
83
|
+
* ? SetValue<M>
|
|
61
84
|
* : K extends 'copySet'
|
|
62
|
-
* ? CopySet
|
|
85
|
+
* ? CopySet<M>
|
|
63
86
|
* : K extends 'copyBag'
|
|
64
|
-
* ?
|
|
87
|
+
* ? CopyBag<M>
|
|
65
88
|
* : never} AssetValueForKind
|
|
66
89
|
*/
|
|
67
90
|
|
|
@@ -94,18 +117,11 @@ export {};
|
|
|
94
117
|
* or AssetKind.SET or AssetKind.COPY_SET (non-fungible)
|
|
95
118
|
*/
|
|
96
119
|
|
|
120
|
+
// XXX hack around JSDoc union handling
|
|
97
121
|
/**
|
|
98
|
-
* @template {AssetKind}
|
|
99
|
-
* @typedef {object}
|
|
100
|
-
*
|
|
101
|
-
* alleged name (such as 'BTC' or 'moola') is provided by the maker of the
|
|
102
|
-
* issuer and should not be trusted as accurate.
|
|
103
|
-
*
|
|
104
|
-
* Every amount created by a particular AmountMath will share the same brand,
|
|
105
|
-
* but recipients cannot rely on the brand to verify that a purported amount
|
|
106
|
-
* represents the issuer they intended, since the same brand can be reused by
|
|
107
|
-
* a misbehaving issuer.
|
|
108
|
-
* @property {(allegedIssuer: ERef<Issuer>) => Promise<boolean>} isMyIssuer
|
|
122
|
+
* @template {AssetKind} K
|
|
123
|
+
* @typedef {object} BrandMethods
|
|
124
|
+
* @property {(allegedIssuer: ERef<Issuer<K>>) => Promise<boolean>} isMyIssuer
|
|
109
125
|
* Should be used with `issuer.getBrand` to ensure an issuer and brand match.
|
|
110
126
|
* @property {() => string} getAllegedName
|
|
111
127
|
* @property {() => DisplayInfo<K>} getDisplayInfo Give information to UI on how
|
|
@@ -113,6 +129,19 @@ export {};
|
|
|
113
129
|
* @property {() => Pattern} getAmountShape
|
|
114
130
|
*/
|
|
115
131
|
|
|
132
|
+
/**
|
|
133
|
+
* @template {AssetKind} [K=AssetKind]
|
|
134
|
+
* @typedef {RemotableObject & BrandMethods<K>} Brand The brand identifies the
|
|
135
|
+
* kind of issuer, and has a function to get the alleged name for the kind of
|
|
136
|
+
* asset described. The alleged name (such as 'BTC' or 'moola') is provided by
|
|
137
|
+
* the maker of the issuer and should not be trusted as accurate.
|
|
138
|
+
*
|
|
139
|
+
* Every amount created by a particular issuer will share the same brand, but
|
|
140
|
+
* recipients cannot rely on the brand to verify that a purported amount
|
|
141
|
+
* represents the issuer they intended, since the same brand can be reused by
|
|
142
|
+
* a misbehaving issuer.
|
|
143
|
+
*/
|
|
144
|
+
|
|
116
145
|
// /////////////////////////// Issuer //////////////////////////////////////////
|
|
117
146
|
|
|
118
147
|
/**
|
|
@@ -124,13 +153,14 @@ export {};
|
|
|
124
153
|
*/
|
|
125
154
|
/**
|
|
126
155
|
* @template {AssetKind} K
|
|
156
|
+
* @template {Key} [M=Key] member kind, for Amounts that have member values
|
|
127
157
|
* @callback IssuerGetAmountOf Get the amount of digital assets in the payment.
|
|
128
158
|
* Because the payment is not trusted, we cannot call a method on it directly,
|
|
129
159
|
* and must use the issuer instead.
|
|
130
160
|
*
|
|
131
161
|
* If the payment is a promise, the operation will proceed upon fulfillment.
|
|
132
|
-
* @param {ERef<Payment
|
|
133
|
-
* @returns {Promise<Amount<K>>}
|
|
162
|
+
* @param {ERef<Payment<K, M>>} payment
|
|
163
|
+
* @returns {Promise<Amount<K, M>>}
|
|
134
164
|
*/
|
|
135
165
|
|
|
136
166
|
/**
|
|
@@ -153,13 +183,9 @@ export {};
|
|
|
153
183
|
*/
|
|
154
184
|
|
|
155
185
|
/**
|
|
156
|
-
* @template {AssetKind}
|
|
157
|
-
* @
|
|
158
|
-
*
|
|
159
|
-
* (splitting payments, combining payments, burning payments, and claiming
|
|
160
|
-
* payments exclusively). The issuer should be gotten from a trusted source
|
|
161
|
-
* and then relied upon as the decider of whether an untrusted payment is
|
|
162
|
-
* valid.
|
|
186
|
+
* @template {AssetKind} K
|
|
187
|
+
* @template {Key} M
|
|
188
|
+
* @typedef {object} IssuerMethods Work around JSDoc union handling
|
|
163
189
|
* @property {() => Brand<K>} getBrand Get the Brand for this Issuer. The Brand
|
|
164
190
|
* indicates the type of digital asset and is shared by the mint, the issuer,
|
|
165
191
|
* and any purses and payments of this particular kind. The brand is not
|
|
@@ -167,16 +193,28 @@ export {};
|
|
|
167
193
|
* alone. Fake digital assets and amount can use another issuer's brand.
|
|
168
194
|
* @property {() => string} getAllegedName Get the allegedName for this
|
|
169
195
|
* mint/issuer
|
|
170
|
-
* @property {() =>
|
|
171
|
-
*
|
|
196
|
+
* @property {() => K} getAssetKind Get the kind of MathHelpers used by this
|
|
197
|
+
* Issuer.
|
|
172
198
|
* @property {() => DisplayInfo<K>} getDisplayInfo Give information to UI on how
|
|
173
199
|
* to display amounts for this issuer.
|
|
174
|
-
* @property {() => Purse<K>} makeEmptyPurse Make an empty purse of this
|
|
200
|
+
* @property {() => Purse<K, M>} makeEmptyPurse Make an empty purse of this
|
|
201
|
+
* brand.
|
|
175
202
|
* @property {IssuerIsLive} isLive
|
|
176
|
-
* @property {IssuerGetAmountOf<K>} getAmountOf
|
|
203
|
+
* @property {IssuerGetAmountOf<K, M>} getAmountOf
|
|
177
204
|
* @property {IssuerBurn} burn
|
|
178
205
|
*/
|
|
179
206
|
|
|
207
|
+
/**
|
|
208
|
+
* @template {AssetKind} [K=AssetKind]
|
|
209
|
+
* @template {Key} [M=Key] member kind, for Amounts that have member values
|
|
210
|
+
* @typedef {RemotableObject & IssuerMethods<K, M>} Issuer The issuer cannot
|
|
211
|
+
* mint a new amount, but it can create empty purses and payments. The issuer
|
|
212
|
+
* can also transform payments (splitting payments, combining payments,
|
|
213
|
+
* burning payments, and claiming payments exclusively). The issuer should be
|
|
214
|
+
* gotten from a trusted source and then relied upon as the decider of whether
|
|
215
|
+
* an untrusted payment is valid.
|
|
216
|
+
*/
|
|
217
|
+
|
|
180
218
|
/**
|
|
181
219
|
* @template {AssetKind} [K=AssetKind]
|
|
182
220
|
* @typedef {object} PaymentLedger
|
|
@@ -190,12 +228,13 @@ export {};
|
|
|
190
228
|
|
|
191
229
|
/**
|
|
192
230
|
* @template {AssetKind} [K=AssetKind]
|
|
231
|
+
* @template {Key} [M=Key] member kind, for Amounts that have member values
|
|
193
232
|
* @typedef {object} IssuerKit
|
|
194
|
-
* @property {Mint<K>} mint
|
|
195
|
-
* @property {Purse<K>} mintRecoveryPurse Externally useful only if this
|
|
196
|
-
* uses recovery sets. Can be used to get the recovery set associated
|
|
197
|
-
* minted payments that are still live.
|
|
198
|
-
* @property {Issuer<K>} issuer
|
|
233
|
+
* @property {Mint<K, M>} mint
|
|
234
|
+
* @property {Purse<K, M>} mintRecoveryPurse Externally useful only if this
|
|
235
|
+
* issuer uses recovery sets. Can be used to get the recovery set associated
|
|
236
|
+
* with minted payments that are still live.
|
|
237
|
+
* @property {Issuer<K, M>} issuer
|
|
199
238
|
* @property {Brand<K>} brand
|
|
200
239
|
* @property {DisplayInfo} displayInfo
|
|
201
240
|
*/
|
|
@@ -216,10 +255,11 @@ export {};
|
|
|
216
255
|
|
|
217
256
|
/**
|
|
218
257
|
* @template {AssetKind} [K=AssetKind]
|
|
258
|
+
* @template {Key} [M=Key] member kind, for Amounts that have member values
|
|
219
259
|
* @typedef {object} Mint Holding a Mint carries the right to issue new digital
|
|
220
260
|
* assets. These assets all have the same kind, which is called a Brand.
|
|
221
|
-
* @property {() => Issuer<K>} getIssuer Gets the Issuer for this mint.
|
|
222
|
-
* @property {(newAmount: Amount<K>) => Payment<K>} mintPayment Creates a new
|
|
261
|
+
* @property {() => Issuer<K, M>} getIssuer Gets the Issuer for this mint.
|
|
262
|
+
* @property {(newAmount: Amount<K>) => Payment<K, M>} mintPayment Creates a new
|
|
223
263
|
* Payment containing newly minted amount.
|
|
224
264
|
*/
|
|
225
265
|
|
|
@@ -261,40 +301,42 @@ export {};
|
|
|
261
301
|
*/
|
|
262
302
|
|
|
263
303
|
/**
|
|
264
|
-
* @template {AssetKind} K
|
|
265
|
-
* @
|
|
266
|
-
* @
|
|
267
|
-
*
|
|
268
|
-
*
|
|
304
|
+
* @template {AssetKind} [K=AssetKind]
|
|
305
|
+
* @template {Key} [M=Key] member kind, for Amounts that have member values
|
|
306
|
+
* @typedef {RemotableObject & PurseMethods<K, M>} Purse Purses hold amount of
|
|
307
|
+
* digital assets of the same brand, but unlike Payments, they are not meant
|
|
308
|
+
* to be sent to others. To transfer digital assets, a Payment should be
|
|
309
|
+
* withdrawn from a Purse. The amount of digital assets in a purse can change
|
|
310
|
+
* through the action of deposit() and withdraw().
|
|
269
311
|
*/
|
|
270
312
|
|
|
271
313
|
/**
|
|
272
314
|
* @template {AssetKind} [K=AssetKind]
|
|
273
|
-
* @
|
|
274
|
-
*
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
*
|
|
278
|
-
*
|
|
279
|
-
* The primary use for Purses and Payments is for currency-like and goods-like
|
|
280
|
-
* digital assets, but they can also be used to represent other kinds of
|
|
281
|
-
* rights, such as the right to participate in a particular contract.
|
|
315
|
+
* @template {Key} [M=Key] member kind, for Amounts that have member values
|
|
316
|
+
* @typedef {object} PurseMethods The primary use for Purses and Payments is for
|
|
317
|
+
* currency-like and goods-like digital assets, but they can also be used to
|
|
318
|
+
* represent other kinds of rights, such as the right to participate in a
|
|
319
|
+
* particular contract.
|
|
282
320
|
* @property {() => Brand<K>} getAllegedBrand Get the alleged Brand for this
|
|
283
321
|
* Purse
|
|
284
|
-
* @property {() => Amount<K>} getCurrentAmount Get the amount contained in
|
|
285
|
-
* purse.
|
|
286
|
-
* @property {() => LatestTopic<Amount<K>>} getCurrentAmountNotifier Get a
|
|
287
|
-
* notifier for changes to this purse's balance.
|
|
288
|
-
* @property {
|
|
289
|
-
*
|
|
290
|
-
*
|
|
322
|
+
* @property {() => Amount<K, M>} getCurrentAmount Get the amount contained in
|
|
323
|
+
* this purse.
|
|
324
|
+
* @property {() => LatestTopic<Amount<K, M>>} getCurrentAmountNotifier Get a
|
|
325
|
+
* lossy notifier for changes to this purse's balance.
|
|
326
|
+
* @property {<P extends Payment<K, M>>(
|
|
327
|
+
* payment: P,
|
|
328
|
+
* optAmountShape?: Pattern,
|
|
329
|
+
* ) => P extends Payment<K, M> ? Amount<K, M> : never} deposit
|
|
330
|
+
* Deposit all the contents of payment into this purse, returning the amount. If
|
|
331
|
+
* the optional argument `optAmount` does not equal the amount of digital
|
|
332
|
+
* assets in the payment, throw an error.
|
|
291
333
|
*
|
|
292
334
|
* If payment is a promise, throw an error.
|
|
293
335
|
* @property {() => DepositFacet} getDepositFacet Return an object whose
|
|
294
336
|
* `receive` method deposits to the current Purse.
|
|
295
|
-
* @property {(amount: Amount<K>) => Payment<K>} withdraw Withdraw amount
|
|
296
|
-
* this purse into a new Payment.
|
|
297
|
-
* @property {() => CopySet<Payment<K>>} getRecoverySet The set of payments
|
|
337
|
+
* @property {(amount: Amount<K, M>) => Payment<K, M>} withdraw Withdraw amount
|
|
338
|
+
* from this purse into a new Payment.
|
|
339
|
+
* @property {() => CopySet<Payment<K, M>>} getRecoverySet The set of payments
|
|
298
340
|
* withdrawn from this purse that are still live. These are the payments that
|
|
299
341
|
* can still be recovered in emergencies by, for example, depositing into this
|
|
300
342
|
* purse. Such a deposit action is like canceling an outstanding check because
|
|
@@ -304,22 +346,23 @@ export {};
|
|
|
304
346
|
* fails.
|
|
305
347
|
*
|
|
306
348
|
* Returns an empty set if this issuer does not support recovery sets.
|
|
307
|
-
* @property {() => Amount<K>} recoverAll For use in emergencies, such as
|
|
308
|
-
* back from a traumatic crash and upgrade. This deposits all the
|
|
309
|
-
* this purse's recovery set into the purse itself, returning the
|
|
310
|
-
* of assets recovered.
|
|
349
|
+
* @property {() => Amount<K, M>} recoverAll For use in emergencies, such as
|
|
350
|
+
* coming back from a traumatic crash and upgrade. This deposits all the
|
|
351
|
+
* payments in this purse's recovery set into the purse itself, returning the
|
|
352
|
+
* total amount of assets recovered.
|
|
311
353
|
*
|
|
312
354
|
* Returns an empty amount if this issuer does not support recovery sets.
|
|
313
355
|
*/
|
|
314
356
|
|
|
315
357
|
/**
|
|
316
358
|
* @template {AssetKind} [K=AssetKind]
|
|
317
|
-
* @
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
*
|
|
321
|
-
*
|
|
322
|
-
*
|
|
359
|
+
* @template {Key} [M=Key] member kind, for Amounts that have member values
|
|
360
|
+
* @typedef {RemotableObject & PaymentMethods<K>} Payment Payments hold amount
|
|
361
|
+
* of digital assets of the same brand in transit. Payments can be deposited
|
|
362
|
+
* in purses, split into multiple payments, combined, and claimed (getting an
|
|
363
|
+
* exclusive payment). Payments are linear, meaning that either a payment has
|
|
364
|
+
* the same amount of digital assets it started with, or it is used up
|
|
365
|
+
* entirely. It is impossible to partially use a payment.
|
|
323
366
|
*
|
|
324
367
|
* Payments are often received from other actors and therefore should not be
|
|
325
368
|
* trusted themselves. To get the amount of digital assets in a payment, use
|
|
@@ -328,6 +371,11 @@ export {};
|
|
|
328
371
|
* Payments can be converted to Purses by getting a trusted issuer and calling
|
|
329
372
|
* `issuer.makeEmptyPurse()` to create a purse, then
|
|
330
373
|
* `purse.deposit(payment)`.
|
|
374
|
+
*/
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* @template {AssetKind} [K=AssetKind]
|
|
378
|
+
* @typedef {object} PaymentMethods
|
|
331
379
|
* @property {() => Brand<K>} getAllegedBrand Get the allegedBrand, indicating
|
|
332
380
|
* the type of digital asset this payment purports to be, and which issuer to
|
|
333
381
|
* use. Because payments are not trusted, any method calls on payments should
|
|
@@ -366,4 +414,7 @@ export {};
|
|
|
366
414
|
|
|
367
415
|
/** @typedef {bigint} NatValue */
|
|
368
416
|
|
|
369
|
-
/**
|
|
417
|
+
/**
|
|
418
|
+
* @template {Key} [K=Key]
|
|
419
|
+
* @typedef {K[]} SetValue
|
|
420
|
+
*/
|