@agoric/ertp 0.16.3-u13.0 → 0.16.3-u16.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 (53) hide show
  1. package/exported.d.ts +37 -0
  2. package/exported.js +2 -1
  3. package/package.json +35 -26
  4. package/src/amountMath.d.ts +44 -31
  5. package/src/amountMath.d.ts.map +1 -1
  6. package/src/amountMath.js +130 -120
  7. package/src/amountStore.d.ts +9 -0
  8. package/src/amountStore.d.ts.map +1 -0
  9. package/src/amountStore.js +34 -0
  10. package/src/displayInfo.d.ts +3 -0
  11. package/src/displayInfo.d.ts.map +1 -1
  12. package/src/displayInfo.js +2 -0
  13. package/src/index.js +8 -0
  14. package/src/issuerKit.d.ts +30 -6
  15. package/src/issuerKit.d.ts.map +1 -1
  16. package/src/issuerKit.js +218 -76
  17. package/src/legacy-payment-helpers.d.ts +6 -1
  18. package/src/legacy-payment-helpers.d.ts.map +1 -1
  19. package/src/legacy-payment-helpers.js +33 -32
  20. package/src/mathHelpers/copyBagMathHelpers.d.ts +3 -4
  21. package/src/mathHelpers/copyBagMathHelpers.d.ts.map +1 -1
  22. package/src/mathHelpers/copyBagMathHelpers.js +4 -5
  23. package/src/mathHelpers/copySetMathHelpers.d.ts +3 -3
  24. package/src/mathHelpers/copySetMathHelpers.d.ts.map +1 -1
  25. package/src/mathHelpers/copySetMathHelpers.js +6 -4
  26. package/src/mathHelpers/natMathHelpers.d.ts +8 -7
  27. package/src/mathHelpers/natMathHelpers.d.ts.map +1 -1
  28. package/src/mathHelpers/natMathHelpers.js +7 -8
  29. package/src/mathHelpers/setMathHelpers.d.ts +2 -0
  30. package/src/mathHelpers/setMathHelpers.d.ts.map +1 -1
  31. package/src/mathHelpers/setMathHelpers.js +2 -1
  32. package/src/payment.d.ts +4 -2
  33. package/src/payment.d.ts.map +1 -1
  34. package/src/payment.js +6 -7
  35. package/src/paymentLedger.d.ts +6 -2
  36. package/src/paymentLedger.d.ts.map +1 -1
  37. package/src/paymentLedger.js +71 -90
  38. package/src/purse.d.ts +19 -9
  39. package/src/purse.d.ts.map +1 -1
  40. package/src/purse.js +86 -25
  41. package/src/transientNotifier.d.ts +1 -1
  42. package/src/transientNotifier.d.ts.map +1 -1
  43. package/src/transientNotifier.js +5 -0
  44. package/src/typeGuards.d.ts +41 -9
  45. package/src/typeGuards.d.ts.map +1 -1
  46. package/src/typeGuards.js +38 -43
  47. package/src/types.d.ts +250 -215
  48. package/src/types.d.ts.map +1 -1
  49. package/src/types.js +305 -326
  50. package/CHANGELOG.md +0 -767
  51. package/src/types-ambient.d.ts +0 -376
  52. package/src/types-ambient.d.ts.map +0 -1
  53. package/src/types-ambient.js +0 -440
package/src/amountMath.js CHANGED
@@ -6,12 +6,22 @@ import { setMathHelpers } from './mathHelpers/setMathHelpers.js';
6
6
  import { copySetMathHelpers } from './mathHelpers/copySetMathHelpers.js';
7
7
  import { copyBagMathHelpers } from './mathHelpers/copyBagMathHelpers.js';
8
8
 
9
+ /**
10
+ * @import {CopyBag, CopySet} from '@endo/patterns';
11
+ * @import {Amount, AssetKind, AmountValue, AssetKindForValue, AssetValueForKind, Brand, CopyBagAmount, CopySetAmount, MathHelpers, NatAmount, NatValue, SetAmount, SetValue} from './types.js';
12
+ */
13
+
9
14
  const { quote: q, Fail } = assert;
10
15
 
11
16
  /**
12
17
  * Constants for the kinds of assets we support.
13
18
  *
14
- * @type {{ NAT: 'nat', SET: 'set', COPY_SET: 'copySet', COPY_BAG: 'copyBag' }}
19
+ * @type {{
20
+ * NAT: 'nat';
21
+ * SET: 'set';
22
+ * COPY_SET: 'copySet';
23
+ * COPY_BAG: 'copyBag';
24
+ * }}
15
25
  */
16
26
  const AssetKind = harden({
17
27
  NAT: 'nat',
@@ -21,9 +31,7 @@ const AssetKind = harden({
21
31
  });
22
32
  const assetKindNames = harden(Object.values(AssetKind).sort());
23
33
 
24
- /**
25
- * @param {AssetKind} allegedAK
26
- */
34
+ /** @param {AssetKind} allegedAK */
27
35
  const assertAssetKind = allegedAK => {
28
36
  assetKindNames.includes(allegedAK) ||
29
37
  Fail`The assetKind ${allegedAK} must be one of ${q(assetKindNames)}`;
@@ -31,42 +39,37 @@ const assertAssetKind = allegedAK => {
31
39
  harden(assertAssetKind);
32
40
 
33
41
  /**
34
- * Amounts describe digital assets. From an amount, you can learn the
35
- * brand of digital asset as well as "how much" or "how many". Amounts
36
- * have two parts: a brand (loosely speaking, the type of digital
37
- * asset) and the value (the answer to "how much"). For example, in
38
- * the phrase "5 bucks", "bucks" takes the role of the brand and the
39
- * value is 5. Amounts can describe fungible and non-fungible digital
40
- * assets. Amounts are pass-by-copy and can be made by and sent to
41
- * anyone.
42
+ * Amounts describe digital assets. From an amount, you can learn the brand of
43
+ * digital asset as well as "how much" or "how many". Amounts have two parts: a
44
+ * brand (loosely speaking, the type of digital asset) and the value (the answer
45
+ * to "how much"). For example, in the phrase "5 bucks", "bucks" takes the role
46
+ * of the brand and the value is 5. Amounts can describe fungible and
47
+ * non-fungible digital assets. Amounts are pass-by-copy and can be made by and
48
+ * sent to anyone.
42
49
  *
43
- * The issuer is the authoritative source of the amount in payments
44
- * and purses. The issuer must be able to do things such as add
45
- * digital assets to a purse and withdraw digital assets from a purse.
46
- * To do so, it must know how to add and subtract digital assets.
47
- * Rather than hard-coding a particular solution, we chose to
48
- * parameterize the issuer with a collection of polymorphic functions,
49
- * which we call `AmountMath`. These math functions include concepts
50
+ * The issuer is the authoritative source of the amount in payments and purses.
51
+ * The issuer must be able to do things such as add digital assets to a purse
52
+ * and withdraw digital assets from a purse. To do so, it must know how to add
53
+ * and subtract digital assets. Rather than hard-coding a particular solution,
54
+ * we chose to parameterize the issuer with a collection of polymorphic
55
+ * functions, which we call `AmountMath`. These math functions include concepts
50
56
  * like addition, subtraction, and greater than or equal to.
51
57
  *
52
- * We also want to make sure there is no confusion as to what kind of
53
- * asset we are using. Thus, AmountMath includes checks of the
54
- * `brand`, the unique identifier for the type of digital asset. If
55
- * the wrong brand is used in AmountMath, an error is thrown and the
56
- * operation does not succeed.
58
+ * We also want to make sure there is no confusion as to what kind of asset we
59
+ * are using. Thus, AmountMath includes checks of the `brand`, the unique
60
+ * identifier for the type of digital asset. If the wrong brand is used in
61
+ * AmountMath, an error is thrown and the operation does not succeed.
57
62
  *
58
- * AmountMath uses mathHelpers to do most of the work, but then adds
59
- * the brand to the result. The function `value` gets the value from
60
- * the amount by removing the brand (amount -> value), and the
61
- * function `make` adds the brand to produce an amount (value ->
62
- * amount). The function `coerce` takes an amount and checks it,
63
- * returning an amount (amount -> amount).
63
+ * AmountMath uses mathHelpers to do most of the work, but then adds the brand
64
+ * to the result. The function `value` gets the value from the amount by
65
+ * removing the brand (amount -> value), and the function `make` adds the brand
66
+ * to produce an amount (value -> amount). The function `coerce` takes an amount
67
+ * and checks it, returning an amount (amount -> amount).
64
68
  *
65
- * Each issuer of digital assets has an associated brand in a
66
- * one-to-one mapping. In untrusted contexts, such as in analyzing
67
- * payments and amounts, we can get the brand and find the issuer
68
- * which matches the brand. The issuer and the brand mutually validate
69
- * each other.
69
+ * Each issuer of digital assets has an associated brand in a one-to-one
70
+ * mapping. In untrusted contexts, such as in analyzing payments and amounts, we
71
+ * can get the brand and find the issuer which matches the brand. The issuer and
72
+ * the brand mutually validate each other.
70
73
  */
71
74
 
72
75
  const helpers = {
@@ -76,26 +79,19 @@ const helpers = {
76
79
  copyBag: copyBagMathHelpers,
77
80
  };
78
81
 
79
- /**
80
- * @template {AmountValue} V
81
- * @type {(value: V) => AssetKindForValue<V>}
82
- */
82
+ /** @type {(value: unknown) => 'nat' | 'set' | 'copySet' | 'copyBag'} } */
83
83
  const assertValueGetAssetKind = value => {
84
84
  const passStyle = passStyleOf(value);
85
85
  if (passStyle === 'bigint') {
86
- // @ts-expect-error cast
87
86
  return 'nat';
88
87
  }
89
88
  if (passStyle === 'copyArray') {
90
- // @ts-expect-error cast
91
89
  return 'set';
92
90
  }
93
91
  if (matches(value, M.set())) {
94
- // @ts-expect-error cast
95
92
  return 'copySet';
96
93
  }
97
94
  if (matches(value, M.bag())) {
98
- // @ts-expect-error cast
99
95
  return 'copyBag';
100
96
  }
101
97
  // TODO This isn't quite the right error message, in case valuePassStyle
@@ -113,7 +109,7 @@ const assertValueGetAssetKind = value => {
113
109
  *
114
110
  * Made available only for testing, but it is harmless for other uses.
115
111
  *
116
- * @template {AmountValue} V
112
+ * @template V
117
113
  * @param {V} value
118
114
  * @returns {MathHelpers<V>}
119
115
  */
@@ -137,7 +133,7 @@ const optionalBrandCheck = (allegedBrand, brand) => {
137
133
  * @param {Amount<K>} leftAmount
138
134
  * @param {Amount<K>} rightAmount
139
135
  * @param {Brand<K> | undefined} brand
140
- * @returns {MathHelpers<*>}
136
+ * @returns {MathHelpers<any>}
141
137
  */
142
138
  const checkLRAndGetHelpers = (leftAmount, rightAmount, brand = undefined) => {
143
139
  assertRecord(leftAmount, 'leftAmount');
@@ -172,11 +168,11 @@ const coerceLR = (h, leftAmount, rightAmount) => {
172
168
  };
173
169
 
174
170
  /**
175
- * Returns true if the leftAmount is greater than or equal to the
176
- * rightAmount. The notion of "greater than or equal to" depends
177
- * on the kind of amount, as defined by the MathHelpers. For example,
178
- * whether rectangle A is greater than rectangle B depends on whether rectangle
179
- * A includes rectangle B as defined by the logic in MathHelpers.
171
+ * Returns true if the leftAmount is greater than or equal to the rightAmount.
172
+ * The notion of "greater than or equal to" depends on the kind of amount, as
173
+ * defined by the MathHelpers. For example, whether rectangle A is greater than
174
+ * rectangle B depends on whether rectangle A includes rectangle B as defined by
175
+ * the logic in MathHelpers.
180
176
  *
181
177
  * @template {AssetKind} K
182
178
  * @param {Amount<K>} leftAmount
@@ -194,34 +190,48 @@ const isGTE = (leftAmount, rightAmount, brand = undefined) => {
194
190
  *
195
191
  * Amounts are the canonical description of tradable goods. They are manipulated
196
192
  * by issuers and mints, and represent the goods and currency carried by purses
197
- * and
198
- * payments. They can be used to represent things like currency, stock, and the
199
- * abstract right to participate in a particular exchange.
193
+ * and payments. They can be used to represent things like currency, stock, and
194
+ * the abstract right to participate in a particular exchange.
200
195
  */
201
196
  const AmountMath = {
197
+ // TODO use overloading to handle when Brand has an AssetKind and when it doesn't.
198
+ // a AmountForValue utility could help DRY those cases.
202
199
  /**
203
200
  * Make an amount from a value by adding the brand.
204
201
  *
205
- * @template {AssetKind} K
206
- * @param {Brand<K>} brand
207
- * @param {AssetValueForKind<K>} allegedValue
208
- * @returns {Amount<K>}
202
+ * Does not verify that the Brand's AssetKind matches the value's.
203
+ *
204
+ * @template {Brand} B
205
+ * @template {NatValue | CopySet | CopyBag | SetValue} V
206
+ * @param {B} brand
207
+ * @param {V} allegedValue
208
+ * @returns {B extends Brand<'nat'>
209
+ * ? NatAmount
210
+ * : V extends NatValue
211
+ * ? NatAmount
212
+ * : V extends CopySet
213
+ * ? CopySetAmount<V['payload'][0]>
214
+ * : V extends CopyBag
215
+ * ? CopyBagAmount<V['payload'][0][0]>
216
+ * : V extends SetValue
217
+ * ? SetAmount<V[0]>
218
+ * : never}
209
219
  */
210
- // allegedValue has a conditional expression for type widening, to prevent V being bound to a a literal like 1n
211
220
  make: (brand, allegedValue) => {
212
221
  assertRemotable(brand, 'brand');
213
222
  const h = assertValueGetHelpers(allegedValue);
214
223
  const value = h.doCoerce(allegedValue);
224
+ // @ts-expect-error cast
215
225
  return harden({ brand, value });
216
226
  },
217
227
  /**
218
- * Make sure this amount is valid enough, and return a corresponding
219
- * valid amount if so.
228
+ * Make sure this amount is valid enough, and return a corresponding valid
229
+ * amount if so.
220
230
  *
221
- * @template {AssetKind} K
222
- * @param {Brand<K>} brand
223
- * @param {Amount<K>} allegedAmount
224
- * @returns {Amount<K>}
231
+ * @template {Amount} A
232
+ * @param {Brand} brand
233
+ * @param {A} allegedAmount
234
+ * @returns {A}
225
235
  */
226
236
  coerce: (brand, allegedAmount) => {
227
237
  assertRemotable(brand, 'brand');
@@ -230,46 +240,47 @@ const AmountMath = {
230
240
  brand === allegedBrand ||
231
241
  Fail`The brand in the allegedAmount ${allegedAmount} in 'coerce' didn't match the specified brand ${brand}.`;
232
242
  // Will throw on inappropriate value
243
+ // @ts-expect-error cast
233
244
  return AmountMath.make(brand, allegedValue);
234
245
  },
235
246
  /**
236
247
  * Extract and return the value.
237
248
  *
238
- * @template {AssetKind} K
239
- * @param {Brand<K>} brand
240
- * @param {Amount<K>} amount
241
- * @returns {AssetValueForKind<K>}
249
+ * @template {Amount} A
250
+ * @param {Brand} brand
251
+ * @param {A} amount
252
+ * @returns {A['value']}
242
253
  */
243
254
  getValue: (brand, amount) => AmountMath.coerce(brand, amount).value,
244
255
  /**
245
- * Return the amount representing an empty amount. This is the
246
- * identity element for MathHelpers.add and MatHelpers.subtract.
256
+ * Return the amount representing an empty amount. This is the identity
257
+ * element for MathHelpers.add and MatHelpers.subtract.
247
258
  *
248
259
  * @type {{
249
260
  * (brand: Brand): Amount<'nat'>;
250
- * <K extends AssetKind>(brand: Brand, assetKind: K): Amount<K>;
261
+ * <K extends AssetKind>(brand: Brand<K>, assetKind: K): Amount<K>;
251
262
  * }}
252
263
  */
253
264
  makeEmpty: (brand, assetKind = /** @type {const} */ ('nat')) => {
254
265
  assertRemotable(brand, 'brand');
255
266
  assertAssetKind(assetKind);
256
267
  const value = helpers[assetKind].doMakeEmpty();
268
+ // @ts-expect-error XXX narrowing from function overload
257
269
  return harden({ brand, value });
258
270
  },
259
271
  /**
260
- * Return the amount representing an empty amount, using another
261
- * amount as the template for the brand and assetKind.
272
+ * Return the amount representing an empty amount, using another amount as the
273
+ * template for the brand and assetKind.
262
274
  *
263
- * @template {AssetKind} K
264
- * @param {Amount<K>} amount
265
- * @returns {Amount<K>}
275
+ * @template {Amount} A
276
+ * @param {A} amount
277
+ * @returns {A}
266
278
  */
267
279
  makeEmptyFromAmount: amount => {
268
280
  assertRecord(amount, 'amount');
269
281
  const { brand, value } = amount;
270
- // @ts-expect-error cast
271
282
  const assetKind = assertValueGetAssetKind(value);
272
- // @ts-expect-error cast (ignore b/c erroring in CI but not my IDE)
283
+ // @ts-expect-error different subtype
273
284
  return AmountMath.makeEmpty(brand, assetKind);
274
285
  },
275
286
  /**
@@ -289,13 +300,13 @@ const AmountMath = {
289
300
  },
290
301
  isGTE,
291
302
  /**
292
- * Returns true if the leftAmount equals the rightAmount. We assume
293
- * that if isGTE is true in both directions, isEqual is also true
303
+ * Returns true if the leftAmount equals the rightAmount. We assume that if
304
+ * isGTE is true in both directions, isEqual is also true
294
305
  *
295
- * @template {AssetKind} K
296
- * @param {Amount<K>} leftAmount
297
- * @param {Amount<K>} rightAmount
298
- * @param {Brand<K>} [brand]
306
+ * @template {Amount} A
307
+ * @param {A} leftAmount
308
+ * @param {A} rightAmount
309
+ * @param {Brand} [brand]
299
310
  * @returns {boolean}
300
311
  */
301
312
  isEqual: (leftAmount, rightAmount, brand = undefined) => {
@@ -306,81 +317,80 @@ const AmountMath = {
306
317
  * Returns a new amount that is the union of both leftAmount and rightAmount.
307
318
  *
308
319
  * For fungible amount this means adding the values. For other kinds of
309
- * amount, it usually means including all of the elements from both
310
- * left and right.
320
+ * amount, it usually means including all of the elements from both left and
321
+ * right.
311
322
  *
312
- * @template {AssetKind} K
313
- * @param {Amount<K>} leftAmount
314
- * @param {Amount<K>} rightAmount
315
- * @param {Brand<K>} [brand]
316
- * @returns {Amount<K>}
323
+ * @template {Amount} A
324
+ * @param {A} leftAmount
325
+ * @param {A} rightAmount
326
+ * @param {Brand} [brand]
327
+ * @returns {A}
317
328
  */
318
329
  add: (leftAmount, rightAmount, brand = undefined) => {
319
330
  const h = checkLRAndGetHelpers(leftAmount, rightAmount, brand);
320
331
  const value = h.doAdd(...coerceLR(h, leftAmount, rightAmount));
332
+ // @ts-expect-error different subtype
321
333
  return harden({ brand: leftAmount.brand, value });
322
334
  },
323
335
  /**
324
- * Returns a new amount that is the leftAmount minus the rightAmount
325
- * (i.e. everything in the leftAmount that is not in the
326
- * rightAmount). If leftAmount doesn't include rightAmount
327
- * (subtraction results in a negative), throw an error. Because the
328
- * left amount must include the right amount, this is NOT equivalent
329
- * to set subtraction.
336
+ * Returns a new amount that is the leftAmount minus the rightAmount (i.e.
337
+ * everything in the leftAmount that is not in the rightAmount). If leftAmount
338
+ * doesn't include rightAmount (subtraction results in a negative), throw an
339
+ * error. Because the left amount must include the right amount, this is NOT
340
+ * equivalent to set subtraction.
330
341
  *
331
- * @template {AssetKind} K
332
- * @param {Amount<K>} leftAmount
333
- * @param {Amount<K>} rightAmount
334
- * @param {Brand<K>} [brand]
335
- * @returns {Amount<K>}
342
+ * @template {Amount} L
343
+ * @template {Amount} R
344
+ * @param {L} leftAmount
345
+ * @param {R} rightAmount
346
+ * @param {Brand} [brand]
347
+ * @returns {L extends R ? L : never}
336
348
  */
337
349
  subtract: (leftAmount, rightAmount, brand = undefined) => {
338
350
  const h = checkLRAndGetHelpers(leftAmount, rightAmount, brand);
339
351
  const value = h.doSubtract(...coerceLR(h, leftAmount, rightAmount));
352
+ // @ts-expect-error different subtype
340
353
  return harden({ brand: leftAmount.brand, value });
341
354
  },
342
355
  /**
343
356
  * Returns the min value between x and y using isGTE
344
357
  *
345
- * @template {AssetKind} K
346
- * @param {Amount<K>} x
347
- * @param {Amount<K>} y
348
- * @param {Brand<K>} [brand]
349
- * @returns {Amount<K>}
358
+ * @template {Amount} A
359
+ * @param {A} x
360
+ * @param {A} y
361
+ * @param {Brand} [brand]
362
+ * @returns {A}
350
363
  */
351
364
  min: (x, y, brand = undefined) =>
352
365
  // eslint-disable-next-line no-nested-ternary
353
366
  isGTE(x, y, brand)
354
367
  ? y
355
368
  : isGTE(y, x, brand)
356
- ? x
357
- : Fail`${x} and ${y} are incomparable`,
369
+ ? x
370
+ : Fail`${x} and ${y} are incomparable`,
358
371
  /**
359
372
  * Returns the max value between x and y using isGTE
360
373
  *
361
- * @template {AssetKind} K
362
- * @param {Amount<K>} x
363
- * @param {Amount<K>} y
364
- * @param {Brand<K>} [brand]
365
- * @returns {Amount<K>}
374
+ * @template {Amount} A
375
+ * @param {A} x
376
+ * @param {A} y
377
+ * @param {Brand} [brand]
378
+ * @returns {A}
366
379
  */
367
380
  max: (x, y, brand = undefined) =>
368
381
  // eslint-disable-next-line no-nested-ternary
369
382
  isGTE(x, y, brand)
370
383
  ? x
371
384
  : isGTE(y, x)
372
- ? y
373
- : Fail`${x} and ${y} are incomparable`,
385
+ ? y
386
+ : Fail`${x} and ${y} are incomparable`,
374
387
  };
375
388
  harden(AmountMath);
376
389
 
377
- /**
378
- * @param {Amount} amount
379
- */
390
+ /** @param {Amount} amount */
380
391
  const getAssetKind = amount => {
381
392
  assertRecord(amount, 'amount');
382
393
  const { value } = amount;
383
- // @ts-expect-error cast (ignore b/c erroring in CI but not my IDE)
384
394
  return assertValueGetAssetKind(value);
385
395
  };
386
396
  harden(getAssetKind);
@@ -0,0 +1,9 @@
1
+ export function makeAmountStore<K extends AssetKind = AssetKind>(state: object, key: string): AmountStore<K>;
2
+ export type AmountStore<K extends AssetKind = AssetKind> = {
3
+ getAmount: () => Amount<K>;
4
+ increment: (delta: Amount<K>) => void;
5
+ decrement: (delta: Amount<K>) => boolean;
6
+ };
7
+ import type { AssetKind } from './types.js';
8
+ import type { Amount } from './types.js';
9
+ //# sourceMappingURL=amountStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"amountStore.d.ts","sourceRoot":"","sources":["amountStore.js"],"names":[],"mappings":"AAkBO,gCALmB,CAAC,SAAd,SAAW,qBACb,MAAM,OACN,MAAM,GACJ,WAAW,CAAC,CAAC,CAAC,CAgB1B;wBA3ByB,CAAC,SAAd,SAAW;eAEV,MAAM,OAAO,CAAC,CAAC;eACf,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,KAAK,IAAI;eAC1B,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,KAAK,OAAO;;+BAPiE,YAAY;4BAAZ,YAAY"}
@@ -0,0 +1,34 @@
1
+ import { AmountMath } from './amountMath.js';
2
+
3
+ /** @import {Amount, AssetKind, AmountValue, AssetKindForValue, AssetValueForKind, Brand, MathHelpers} from './types.js' */
4
+
5
+ /**
6
+ * @template {AssetKind} [K=AssetKind]
7
+ * @typedef {object} AmountStore
8
+ * @property {() => Amount<K>} getAmount
9
+ * @property {(delta: Amount<K>) => void} increment
10
+ * @property {(delta: Amount<K>) => boolean} decrement
11
+ */
12
+
13
+ /**
14
+ * @template {AssetKind} [K=AssetKind]
15
+ * @param {object} state
16
+ * @param {string} key
17
+ * @returns {AmountStore<K>}
18
+ */
19
+ export const makeAmountStore = (state, key) => {
20
+ return harden({
21
+ getAmount: () => state[key],
22
+ increment: delta => {
23
+ state[key] = AmountMath.add(state[key], delta);
24
+ },
25
+ decrement: delta => {
26
+ if (AmountMath.isGTE(state[key], delta)) {
27
+ state[key] = AmountMath.subtract(state[key], delta);
28
+ return true;
29
+ }
30
+ return false;
31
+ },
32
+ });
33
+ };
34
+ harden(makeAmountStore);
@@ -1,2 +1,5 @@
1
1
  export function coerceDisplayInfo(allegedDisplayInfo: AdditionalDisplayInfo, assetKind: AssetKind): DisplayInfo;
2
+ import type { AdditionalDisplayInfo } from './types.js';
3
+ import type { AssetKind } from './types.js';
4
+ import type { DisplayInfo } from './types.js';
2
5
  //# sourceMappingURL=displayInfo.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"displayInfo.d.ts","sourceRoot":"","sources":["displayInfo.js"],"names":[],"mappings":"AAYO,sDAJI,qBAAqB,aACrB,SAAS,GACP,WAAW,CAiBvB"}
1
+ {"version":3,"file":"displayInfo.d.ts","sourceRoot":"","sources":["displayInfo.js"],"names":[],"mappings":"AAcO,sDAJI,qBAAqB,aACrB,SAAS,GACP,WAAW,CAiBvB;2CAtBgE,YAAY;+BAAZ,YAAY;iCAAZ,YAAY"}
@@ -5,6 +5,8 @@ import { mustMatch } from '@agoric/store';
5
5
 
6
6
  import { DisplayInfoShape } from './typeGuards.js';
7
7
 
8
+ /** @import {AdditionalDisplayInfo, AssetKind, DisplayInfo} from './types.js' */
9
+
8
10
  /**
9
11
  * @param {AdditionalDisplayInfo} allegedDisplayInfo
10
12
  * @param {AssetKind} assetKind
package/src/index.js CHANGED
@@ -1,5 +1,13 @@
1
1
  // @jessie-check
2
+ /// <reference types="@agoric/internal/exported" />
2
3
 
3
4
  export * from './amountMath.js';
4
5
  export * from './issuerKit.js';
5
6
  export * from './typeGuards.js';
7
+
8
+ /**
9
+ * Importing Baggage from `@agoric/ertp` is deprecated. Import Baggage from
10
+ * `@agoric/vat-data` instead
11
+ *
12
+ * @import {Baggage} from '@agoric/vat-data'
13
+ */
@@ -1,19 +1,43 @@
1
- export function prepareIssuerKit<K extends AssetKind>(issuerBaggage: MapStore<string, unknown>, optShutdownWithFailure?: import("@agoric/swingset-vat").ShutdownWithFailure | undefined): IssuerKit<K>;
2
- export function hasIssuer(baggage: MapStore<string, unknown>): any;
3
- export function makeDurableIssuerKit<K extends AssetKind>(issuerBaggage: MapStore<string, unknown>, name: string, assetKind?: K | undefined, displayInfo?: AdditionalDisplayInfo | undefined, optShutdownWithFailure?: import("@agoric/swingset-vat").ShutdownWithFailure | undefined, { elementShape }?: Partial<{
1
+ export function upgradeIssuerKit<K extends import("./types.js").AssetKind>(issuerBaggage: import("@agoric/vat-data").Baggage, optShutdownWithFailure?: ShutdownWithFailure | undefined, recoverySetsOption?: RecoverySetsOption | undefined): IssuerKit<K>;
2
+ export function hasIssuer(baggage: import("@agoric/vat-data").Baggage): boolean;
3
+ export function makeDurableIssuerKit<K extends import("./types.js").AssetKind>(issuerBaggage: import("@agoric/vat-data").Baggage, name: string, assetKind?: K | undefined, displayInfo?: AdditionalDisplayInfo | undefined, optShutdownWithFailure?: ShutdownWithFailure | undefined, { elementShape, recoverySetsOption }?: Partial<{
4
4
  elementShape: Pattern;
5
+ recoverySetsOption: RecoverySetsOption;
5
6
  }> | undefined): IssuerKit<K>;
6
- export function makeIssuerKit<K extends AssetKind = "nat">(name: string, assetKind?: K | undefined, displayInfo?: AdditionalDisplayInfo | undefined, optShutdownWithFailure?: import("@agoric/swingset-vat").ShutdownWithFailure | undefined, { elementShape }?: Partial<{
7
+ export function prepareIssuerKit<K extends import("./types.js").AssetKind>(issuerBaggage: import("@agoric/vat-data").Baggage, name: string, assetKind?: K | undefined, displayInfo?: AdditionalDisplayInfo | undefined, optShutdownWithFailure?: ShutdownWithFailure | undefined, options?: Partial<{
7
8
  elementShape: Pattern;
9
+ recoverySetsOption: RecoverySetsOption;
8
10
  }> | undefined): IssuerKit<K>;
9
- export type Baggage = import('@agoric/vat-data').Baggage;
10
- export type IssuerRecord<K extends AssetKind> = {
11
+ export function makeIssuerKit<K extends import("./types.js").AssetKind = "nat">(name: string, assetKind?: K | undefined, displayInfo?: AdditionalDisplayInfo | undefined, optShutdownWithFailure?: ShutdownWithFailure | undefined, { elementShape, recoverySetsOption }?: Partial<{
12
+ elementShape: Pattern;
13
+ recoverySetsOption: RecoverySetsOption;
14
+ }> | undefined): IssuerKit<K, any>;
15
+ export type IssuerRecord<K extends import("./types.js").AssetKind> = {
11
16
  name: string;
12
17
  assetKind: K;
13
18
  displayInfo: AdditionalDisplayInfo;
14
19
  elementShape: Pattern;
15
20
  };
21
+ /**
22
+ * `elementShape`, may only be present for collection-style amounts. If present,
23
+ * it is a `Pattern` that every element of this issuerKits's amounts must
24
+ * satisfy. For example, the Zoe Invitation issuerKit uses an elementShape
25
+ * describing the invitation details for an individual invitation. An invitation
26
+ * purse or payment has an amount that can only be a set of these. (Though
27
+ * typically, the amount of an invitation payment is a singleton set. Such a
28
+ * payment is often referred to in the singular as "an invitation".)
29
+ *
30
+ * `recoverySetsOption` added in upgrade. Note that `IssuerOptionsRecord` is
31
+ * never stored, so we never need to worry about inheriting one from a
32
+ * predecessor predating the introduction of recovery sets. See
33
+ * `RecoverySetsOption` for defaulting behavior.
34
+ */
16
35
  export type IssuerOptionsRecord = Partial<{
17
36
  elementShape: Pattern;
37
+ recoverySetsOption: RecoverySetsOption;
18
38
  }>;
39
+ import type { ShutdownWithFailure } from '@agoric/swingset-vat';
40
+ import type { RecoverySetsOption } from './types.js';
41
+ import type { IssuerKit } from './types.js';
42
+ import type { AdditionalDisplayInfo } from './types.js';
19
43
  //# sourceMappingURL=issuerKit.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"issuerKit.d.ts","sourceRoot":"","sources":["issuerKit.js"],"names":[],"mappings":"AA2FO,uMAMN;AASM,mEAAsD;AAmCtD,0GAbI,MAAM;kBAnBmB,OAAO;8BA4C1C;AA+BM,iEAbI,MAAM;kBA9DmB,OAAO;8BA0FxC;sBA3LW,OAAO,kBAAkB,EAAE,OAAO;;UAKlC,MAAM;eACN,CAAC;iBACD,qBAAqB;kBACrB,OAAO;;kCAyFR,QAAQ;IAAC,YAAY,EAAE,OAAO,CAAA;CAAC,CAAC"}
1
+ {"version":3,"file":"issuerKit.d.ts","sourceRoot":"","sources":["issuerKit.js"],"names":[],"mappings":"AA4GO,iCAbkB,CAAC,SAAb,8BAAW,iBACb,OAAO,kBAAkB,EAAE,OAAO,kHAUhC,UAAU,CAAC,CAAC,CA4BxB;AAQM,mCAFI,OAAO,kBAAkB,EAAE,OAAO,WAEgB;AAoDtD,qCA1BkB,CAAC,SAAb,8BAAW,iBAYb,OAAO,kBAAkB,EAAE,OAAO,QAClC,MAAM;kBAtBE,OAAO;wBACD,kBAAkB;iBAgC9B,UAAU,CAAC,CAAC,CA2BxB;AAiCM,iCA1BkB,CAAC,SAAb,8BAAW,iBAYb,OAAO,kBAAkB,EAAE,OAAO,QAClC,MAAM;kBAhFE,OAAO;wBACD,kBAAkB;iBA0F9B,UAAU,CAAC,CAAC,CAuCxB;AAqCM,8BAzBmB,CAAC,SAAd,8BAAW,gBAYb,MAAM;kBA1JE,OAAO;wBACD,kBAAkB;iBAoK9B,UAAU,CAAC,EAAE,GAAG,CAAC,CAiB3B;yBAtUsB,CAAC,SAAb,8BAAW;UAEV,MAAM;eACN,CAAC;iBACD,qBAAqB;kBACrB,OAAO;;;;;;;;;;;;;;;;kCA0IR,OAAO,CAAC;IACpB,YAAgB,EAAE,OAAO,CAAC;IAC1B,kBAAsB,EAAE,kBAAkB,CAAC;CACxC,CAAC;yCArJkC,sBAAsB;wCAD0B,YAAY;+BAAZ,YAAY;2CAAZ,YAAY"}