@agoric/ertp 0.16.3-other-dev-8f8782b.0 → 0.16.3-other-dev-3eb1a1d.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 (57) hide show
  1. package/exported.d.ts +37 -0
  2. package/exported.js +2 -1
  3. package/package.json +35 -35
  4. package/src/amountMath.d.ts +42 -38
  5. package/src/amountMath.d.ts.map +1 -1
  6. package/src/amountMath.js +131 -127
  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 +3 -1
  13. package/src/index.d.ts +1 -0
  14. package/src/index.js +4 -0
  15. package/src/issuerKit.d.ts +30 -5
  16. package/src/issuerKit.d.ts.map +1 -1
  17. package/src/issuerKit.js +218 -76
  18. package/src/legacy-payment-helpers.d.ts +6 -1
  19. package/src/legacy-payment-helpers.d.ts.map +1 -1
  20. package/src/legacy-payment-helpers.js +34 -34
  21. package/src/mathHelpers/copyBagMathHelpers.d.ts +3 -4
  22. package/src/mathHelpers/copyBagMathHelpers.d.ts.map +1 -1
  23. package/src/mathHelpers/copyBagMathHelpers.js +4 -5
  24. package/src/mathHelpers/copySetMathHelpers.d.ts +3 -3
  25. package/src/mathHelpers/copySetMathHelpers.d.ts.map +1 -1
  26. package/src/mathHelpers/copySetMathHelpers.js +6 -4
  27. package/src/mathHelpers/natMathHelpers.d.ts +8 -7
  28. package/src/mathHelpers/natMathHelpers.d.ts.map +1 -1
  29. package/src/mathHelpers/natMathHelpers.js +8 -9
  30. package/src/mathHelpers/setMathHelpers.d.ts +2 -0
  31. package/src/mathHelpers/setMathHelpers.d.ts.map +1 -1
  32. package/src/mathHelpers/setMathHelpers.js +2 -1
  33. package/src/payment.d.ts +4 -2
  34. package/src/payment.d.ts.map +1 -1
  35. package/src/payment.js +6 -7
  36. package/src/paymentLedger.d.ts +6 -2
  37. package/src/paymentLedger.d.ts.map +1 -1
  38. package/src/paymentLedger.js +76 -95
  39. package/src/purse.d.ts +19 -9
  40. package/src/purse.d.ts.map +1 -1
  41. package/src/purse.js +86 -26
  42. package/src/transientNotifier.d.ts +1 -1
  43. package/src/transientNotifier.d.ts.map +1 -1
  44. package/src/transientNotifier.js +5 -0
  45. package/src/typeGuards.d.ts +60 -13
  46. package/src/typeGuards.d.ts.map +1 -1
  47. package/src/typeGuards.js +69 -57
  48. package/src/types-index.d.ts +2 -0
  49. package/src/types-index.js +2 -0
  50. package/src/types.d.ts +253 -219
  51. package/src/types.d.ts.map +1 -1
  52. package/src/types.ts +468 -0
  53. package/CHANGELOG.md +0 -743
  54. package/src/types-ambient.d.ts +0 -376
  55. package/src/types-ambient.d.ts.map +0 -1
  56. package/src/types-ambient.js +0 -440
  57. package/src/types.js +0 -441
package/src/amountMath.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { q, Fail } from '@endo/errors';
1
2
  import { passStyleOf, assertRemotable, assertRecord } from '@endo/marshal';
2
3
 
3
4
  import { M, matches } from '@agoric/store';
@@ -6,67 +7,65 @@ import { setMathHelpers } from './mathHelpers/setMathHelpers.js';
6
7
  import { copySetMathHelpers } from './mathHelpers/copySetMathHelpers.js';
7
8
  import { copyBagMathHelpers } from './mathHelpers/copyBagMathHelpers.js';
8
9
 
9
- const { quote: q, Fail } = assert;
10
+ /**
11
+ * @import {CopyBag, CopySet} from '@endo/patterns';
12
+ * @import {Amount, AssetValueForKind, Brand, CopyBagAmount, CopySetAmount, MathHelpers, NatAmount, NatValue, SetAmount, SetValue} from './types.js';
13
+ */
10
14
 
15
+ // NB: AssetKind is both a constant for enumerated values and a type for those values.
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
+ * @enum {(typeof AssetKind)[keyof typeof AssetKind]}
15
20
  */
16
- const AssetKind = harden({
21
+ export const AssetKind = /** @type {const} */ ({
17
22
  NAT: 'nat',
18
23
  SET: 'set',
19
24
  COPY_SET: 'copySet',
20
25
  COPY_BAG: 'copyBag',
21
26
  });
27
+ harden(AssetKind);
22
28
  const assetKindNames = harden(Object.values(AssetKind).sort());
23
29
 
24
- /**
25
- * @param {AssetKind} allegedAK
26
- */
27
- const assertAssetKind = allegedAK => {
30
+ /** @param {AssetKind} allegedAK */
31
+ export const assertAssetKind = allegedAK => {
28
32
  assetKindNames.includes(allegedAK) ||
29
33
  Fail`The assetKind ${allegedAK} must be one of ${q(assetKindNames)}`;
30
34
  };
31
35
  harden(assertAssetKind);
32
36
 
33
37
  /**
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.
38
+ * Amounts describe digital assets. From an amount, you can learn the brand of
39
+ * digital asset as well as "how much" or "how many". Amounts have two parts: a
40
+ * brand (loosely speaking, the type of digital asset) and the value (the answer
41
+ * to "how much"). For example, in the phrase "5 bucks", "bucks" takes the role
42
+ * of the brand and the value is 5. Amounts can describe fungible and
43
+ * non-fungible digital assets. Amounts are pass-by-copy and can be made by and
44
+ * sent to anyone.
42
45
  *
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
46
+ * The issuer is the authoritative source of the amount in payments and purses.
47
+ * The issuer must be able to do things such as add digital assets to a purse
48
+ * and withdraw digital assets from a purse. To do so, it must know how to add
49
+ * and subtract digital assets. Rather than hard-coding a particular solution,
50
+ * we chose to parameterize the issuer with a collection of polymorphic
51
+ * functions, which we call `AmountMath`. These math functions include concepts
50
52
  * like addition, subtraction, and greater than or equal to.
51
53
  *
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.
54
+ * We also want to make sure there is no confusion as to what kind of asset we
55
+ * are using. Thus, AmountMath includes checks of the `brand`, the unique
56
+ * identifier for the type of digital asset. If the wrong brand is used in
57
+ * AmountMath, an error is thrown and the operation does not succeed.
57
58
  *
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).
59
+ * AmountMath uses mathHelpers to do most of the work, but then adds the brand
60
+ * to the result. The function `value` gets the value from the amount by
61
+ * removing the brand (amount -> value), and the function `make` adds the brand
62
+ * to produce an amount (value -> amount). The function `coerce` takes an amount
63
+ * and checks it, returning an amount (amount -> amount).
64
64
  *
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.
65
+ * Each issuer of digital assets has an associated brand in a one-to-one
66
+ * mapping. In untrusted contexts, such as in analyzing payments and amounts, we
67
+ * can get the brand and find the issuer which matches the brand. The issuer and
68
+ * the brand mutually validate each other.
70
69
  */
71
70
 
72
71
  const helpers = {
@@ -76,26 +75,19 @@ const helpers = {
76
75
  copyBag: copyBagMathHelpers,
77
76
  };
78
77
 
79
- /**
80
- * @template {AmountValue} V
81
- * @type {(value: V) => AssetKindForValue<V>}
82
- */
78
+ /** @type {(value: unknown) => 'nat' | 'set' | 'copySet' | 'copyBag'} } */
83
79
  const assertValueGetAssetKind = value => {
84
80
  const passStyle = passStyleOf(value);
85
81
  if (passStyle === 'bigint') {
86
- // @ts-expect-error cast
87
82
  return 'nat';
88
83
  }
89
84
  if (passStyle === 'copyArray') {
90
- // @ts-expect-error cast
91
85
  return 'set';
92
86
  }
93
87
  if (matches(value, M.set())) {
94
- // @ts-expect-error cast
95
88
  return 'copySet';
96
89
  }
97
90
  if (matches(value, M.bag())) {
98
- // @ts-expect-error cast
99
91
  return 'copyBag';
100
92
  }
101
93
  // TODO This isn't quite the right error message, in case valuePassStyle
@@ -113,7 +105,7 @@ const assertValueGetAssetKind = value => {
113
105
  *
114
106
  * Made available only for testing, but it is harmless for other uses.
115
107
  *
116
- * @template {AmountValue} V
108
+ * @template V
117
109
  * @param {V} value
118
110
  * @returns {MathHelpers<V>}
119
111
  */
@@ -137,7 +129,7 @@ const optionalBrandCheck = (allegedBrand, brand) => {
137
129
  * @param {Amount<K>} leftAmount
138
130
  * @param {Amount<K>} rightAmount
139
131
  * @param {Brand<K> | undefined} brand
140
- * @returns {MathHelpers<*>}
132
+ * @returns {MathHelpers<any>}
141
133
  */
142
134
  const checkLRAndGetHelpers = (leftAmount, rightAmount, brand = undefined) => {
143
135
  assertRecord(leftAmount, 'leftAmount');
@@ -172,11 +164,11 @@ const coerceLR = (h, leftAmount, rightAmount) => {
172
164
  };
173
165
 
174
166
  /**
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.
167
+ * Returns true if the leftAmount is greater than or equal to the rightAmount.
168
+ * The notion of "greater than or equal to" depends on the kind of amount, as
169
+ * defined by the MathHelpers. For example, whether rectangle A is greater than
170
+ * rectangle B depends on whether rectangle A includes rectangle B as defined by
171
+ * the logic in MathHelpers.
180
172
  *
181
173
  * @template {AssetKind} K
182
174
  * @param {Amount<K>} leftAmount
@@ -194,34 +186,48 @@ const isGTE = (leftAmount, rightAmount, brand = undefined) => {
194
186
  *
195
187
  * Amounts are the canonical description of tradable goods. They are manipulated
196
188
  * 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.
189
+ * and payments. They can be used to represent things like currency, stock, and
190
+ * the abstract right to participate in a particular exchange.
200
191
  */
201
- const AmountMath = {
192
+ export const AmountMath = {
193
+ // TODO use overloading to handle when Brand has an AssetKind and when it doesn't.
194
+ // a AmountForValue utility could help DRY those cases.
202
195
  /**
203
196
  * Make an amount from a value by adding the brand.
204
197
  *
205
- * @template {AssetKind} K
206
- * @param {Brand<K>} brand
207
- * @param {AssetValueForKind<K>} allegedValue
208
- * @returns {Amount<K>}
198
+ * Does not verify that the Brand's AssetKind matches the value's.
199
+ *
200
+ * @template {Brand} B
201
+ * @template {NatValue | CopySet | CopyBag | SetValue} V
202
+ * @param {B} brand
203
+ * @param {V} allegedValue
204
+ * @returns {B extends Brand<'nat'>
205
+ * ? NatAmount
206
+ * : V extends NatValue
207
+ * ? NatAmount
208
+ * : V extends CopySet
209
+ * ? CopySetAmount<V['payload'][0]>
210
+ * : V extends CopyBag
211
+ * ? CopyBagAmount<V['payload'][0][0]>
212
+ * : V extends SetValue
213
+ * ? SetAmount<V[0]>
214
+ * : never}
209
215
  */
210
- // allegedValue has a conditional expression for type widening, to prevent V being bound to a a literal like 1n
211
216
  make: (brand, allegedValue) => {
212
217
  assertRemotable(brand, 'brand');
213
218
  const h = assertValueGetHelpers(allegedValue);
214
219
  const value = h.doCoerce(allegedValue);
220
+ // @ts-expect-error cast
215
221
  return harden({ brand, value });
216
222
  },
217
223
  /**
218
- * Make sure this amount is valid enough, and return a corresponding
219
- * valid amount if so.
224
+ * Make sure this amount is valid enough, and return a corresponding valid
225
+ * amount if so.
220
226
  *
221
- * @template {AssetKind} K
222
- * @param {Brand<K>} brand
223
- * @param {Amount<K>} allegedAmount
224
- * @returns {Amount<K>}
227
+ * @template {Amount} A
228
+ * @param {Brand} brand
229
+ * @param {A} allegedAmount
230
+ * @returns {A}
225
231
  */
226
232
  coerce: (brand, allegedAmount) => {
227
233
  assertRemotable(brand, 'brand');
@@ -230,46 +236,47 @@ const AmountMath = {
230
236
  brand === allegedBrand ||
231
237
  Fail`The brand in the allegedAmount ${allegedAmount} in 'coerce' didn't match the specified brand ${brand}.`;
232
238
  // Will throw on inappropriate value
239
+ // @ts-expect-error cast
233
240
  return AmountMath.make(brand, allegedValue);
234
241
  },
235
242
  /**
236
243
  * Extract and return the value.
237
244
  *
238
- * @template {AssetKind} K
239
- * @param {Brand<K>} brand
240
- * @param {Amount<K>} amount
241
- * @returns {AssetValueForKind<K>}
245
+ * @template {Amount} A
246
+ * @param {Brand} brand
247
+ * @param {A} amount
248
+ * @returns {A['value']}
242
249
  */
243
250
  getValue: (brand, amount) => AmountMath.coerce(brand, amount).value,
244
251
  /**
245
- * Return the amount representing an empty amount. This is the
246
- * identity element for MathHelpers.add and MatHelpers.subtract.
252
+ * Return the amount representing an empty amount. This is the identity
253
+ * element for MathHelpers.add and MatHelpers.subtract.
247
254
  *
248
255
  * @type {{
249
256
  * (brand: Brand): Amount<'nat'>;
250
- * <K extends AssetKind>(brand: Brand, assetKind: K): Amount<K>;
257
+ * <K extends AssetKind>(brand: Brand<K>, assetKind: K): Amount<K>;
251
258
  * }}
252
259
  */
253
260
  makeEmpty: (brand, assetKind = /** @type {const} */ ('nat')) => {
254
261
  assertRemotable(brand, 'brand');
255
262
  assertAssetKind(assetKind);
256
263
  const value = helpers[assetKind].doMakeEmpty();
264
+ // @ts-expect-error XXX narrowing from function overload
257
265
  return harden({ brand, value });
258
266
  },
259
267
  /**
260
- * Return the amount representing an empty amount, using another
261
- * amount as the template for the brand and assetKind.
268
+ * Return the amount representing an empty amount, using another amount as the
269
+ * template for the brand and assetKind.
262
270
  *
263
- * @template {AssetKind} K
264
- * @param {Amount<K>} amount
265
- * @returns {Amount<K>}
271
+ * @template {Amount} A
272
+ * @param {A} amount
273
+ * @returns {A}
266
274
  */
267
275
  makeEmptyFromAmount: amount => {
268
276
  assertRecord(amount, 'amount');
269
277
  const { brand, value } = amount;
270
- // @ts-expect-error cast
271
278
  const assetKind = assertValueGetAssetKind(value);
272
- // @ts-expect-error cast (ignore b/c erroring in CI but not my IDE)
279
+ // @ts-expect-error different subtype
273
280
  return AmountMath.makeEmpty(brand, assetKind);
274
281
  },
275
282
  /**
@@ -289,13 +296,13 @@ const AmountMath = {
289
296
  },
290
297
  isGTE,
291
298
  /**
292
- * Returns true if the leftAmount equals the rightAmount. We assume
293
- * that if isGTE is true in both directions, isEqual is also true
299
+ * Returns true if the leftAmount equals the rightAmount. We assume that if
300
+ * isGTE is true in both directions, isEqual is also true
294
301
  *
295
- * @template {AssetKind} K
296
- * @param {Amount<K>} leftAmount
297
- * @param {Amount<K>} rightAmount
298
- * @param {Brand<K>} [brand]
302
+ * @template {Amount} A
303
+ * @param {A} leftAmount
304
+ * @param {A} rightAmount
305
+ * @param {Brand} [brand]
299
306
  * @returns {boolean}
300
307
  */
301
308
  isEqual: (leftAmount, rightAmount, brand = undefined) => {
@@ -306,83 +313,80 @@ const AmountMath = {
306
313
  * Returns a new amount that is the union of both leftAmount and rightAmount.
307
314
  *
308
315
  * 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.
316
+ * amount, it usually means including all of the elements from both left and
317
+ * right.
311
318
  *
312
- * @template {AssetKind} K
313
- * @param {Amount<K>} leftAmount
314
- * @param {Amount<K>} rightAmount
315
- * @param {Brand<K>} [brand]
316
- * @returns {Amount<K>}
319
+ * @template {Amount} A
320
+ * @param {A} leftAmount
321
+ * @param {A} rightAmount
322
+ * @param {Brand} [brand]
323
+ * @returns {A}
317
324
  */
318
325
  add: (leftAmount, rightAmount, brand = undefined) => {
319
326
  const h = checkLRAndGetHelpers(leftAmount, rightAmount, brand);
320
327
  const value = h.doAdd(...coerceLR(h, leftAmount, rightAmount));
328
+ // @ts-expect-error different subtype
321
329
  return harden({ brand: leftAmount.brand, value });
322
330
  },
323
331
  /**
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.
332
+ * Returns a new amount that is the leftAmount minus the rightAmount (i.e.
333
+ * everything in the leftAmount that is not in the rightAmount). If leftAmount
334
+ * doesn't include rightAmount (subtraction results in a negative), throw an
335
+ * error. Because the left amount must include the right amount, this is NOT
336
+ * equivalent to set subtraction.
330
337
  *
331
- * @template {AssetKind} K
332
- * @param {Amount<K>} leftAmount
333
- * @param {Amount<K>} rightAmount
334
- * @param {Brand<K>} [brand]
335
- * @returns {Amount<K>}
338
+ * @template {Amount} L
339
+ * @template {Amount} R
340
+ * @param {L} leftAmount
341
+ * @param {R} rightAmount
342
+ * @param {Brand} [brand]
343
+ * @returns {L extends R ? L : never}
336
344
  */
337
345
  subtract: (leftAmount, rightAmount, brand = undefined) => {
338
346
  const h = checkLRAndGetHelpers(leftAmount, rightAmount, brand);
339
347
  const value = h.doSubtract(...coerceLR(h, leftAmount, rightAmount));
348
+ // @ts-expect-error different subtype
340
349
  return harden({ brand: leftAmount.brand, value });
341
350
  },
342
351
  /**
343
352
  * Returns the min value between x and y using isGTE
344
353
  *
345
- * @template {AssetKind} K
346
- * @param {Amount<K>} x
347
- * @param {Amount<K>} y
348
- * @param {Brand<K>} [brand]
349
- * @returns {Amount<K>}
354
+ * @template {Amount} A
355
+ * @param {A} x
356
+ * @param {A} y
357
+ * @param {Brand} [brand]
358
+ * @returns {A}
350
359
  */
351
360
  min: (x, y, brand = undefined) =>
352
361
  // eslint-disable-next-line no-nested-ternary
353
362
  isGTE(x, y, brand)
354
363
  ? y
355
364
  : isGTE(y, x, brand)
356
- ? x
357
- : Fail`${x} and ${y} are incomparable`,
365
+ ? x
366
+ : Fail`${x} and ${y} are incomparable`,
358
367
  /**
359
368
  * Returns the max value between x and y using isGTE
360
369
  *
361
- * @template {AssetKind} K
362
- * @param {Amount<K>} x
363
- * @param {Amount<K>} y
364
- * @param {Brand<K>} [brand]
365
- * @returns {Amount<K>}
370
+ * @template {Amount} A
371
+ * @param {A} x
372
+ * @param {A} y
373
+ * @param {Brand} [brand]
374
+ * @returns {A}
366
375
  */
367
376
  max: (x, y, brand = undefined) =>
368
377
  // eslint-disable-next-line no-nested-ternary
369
378
  isGTE(x, y, brand)
370
379
  ? x
371
380
  : isGTE(y, x)
372
- ? y
373
- : Fail`${x} and ${y} are incomparable`,
381
+ ? y
382
+ : Fail`${x} and ${y} are incomparable`,
374
383
  };
375
384
  harden(AmountMath);
376
385
 
377
- /**
378
- * @param {Amount} amount
379
- */
380
- const getAssetKind = amount => {
386
+ /** @param {Amount} amount */
387
+ export const getAssetKind = amount => {
381
388
  assertRecord(amount, 'amount');
382
389
  const { value } = amount;
383
- // @ts-expect-error cast (ignore b/c erroring in CI but not my IDE)
384
390
  return assertValueGetAssetKind(value);
385
391
  };
386
392
  harden(getAssetKind);
387
-
388
- export { AmountMath, AssetKind, getAssetKind, assertAssetKind };
@@ -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;;+BAPN,YAAY;4BAAZ,YAAY"}
@@ -0,0 +1,34 @@
1
+ import { AmountMath } from './amountMath.js';
2
+
3
+ /** @import {Amount, AssetKind} 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"}
@@ -1,10 +1,12 @@
1
1
  // @jessie-check
2
2
 
3
- import { Fail } from '@agoric/assert';
3
+ import { Fail } from '@endo/errors';
4
4
  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.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./amountMath.js";
2
2
  export * from "./issuerKit.js";
3
3
  export * from "./typeGuards.js";
4
+ export * from "./types-index.js";
4
5
  //# sourceMappingURL=index.d.ts.map
package/src/index.js CHANGED
@@ -1,5 +1,9 @@
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
+ // eslint-disable-next-line import/export
9
+ export * from './types-index.js';
@@ -1,19 +1,44 @@
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 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 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 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;
11
+ export function makeIssuerKit<K extends 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>;
10
15
  export type IssuerRecord<K extends 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 { AssetKind } from './amountMath.js';
40
+ import type { ShutdownWithFailure } from '@agoric/swingset-vat';
41
+ import type { RecoverySetsOption } from './types.js';
42
+ import type { IssuerKit } from './types.js';
43
+ import type { AdditionalDisplayInfo } from './types.js';
19
44
  //# 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,SAAZ,SAAU,iBACb,OAAO,kBAAkB,EAAE,OAAO,kHAUhC,UAAU,CAAC,CAAC,CA4BxB;AAQM,mCAFI,OAAO,kBAAkB,EAAE,OAAO,WAEgB;AAoDtD,qCA1BkB,CAAC,SAAZ,SAAU,iBAYb,OAAO,kBAAkB,EAAE,OAAO,QAClC,MAAM;kBAtBE,OAAO;wBACD,kBAAkB;iBAgC9B,UAAU,CAAC,CAAC,CA2BxB;AAiCM,iCA1BkB,CAAC,SAAZ,SAAU,iBAYb,OAAO,kBAAkB,EAAE,OAAO,QAClC,MAAM;kBAhFE,OAAO;wBACD,kBAAkB;iBA0F9B,UAAU,CAAC,CAAC,CAuCxB;AAqCM,8BAzBmB,CAAC,SAAb,SAAU,gBAYb,MAAM;kBA1JE,OAAO;wBACD,kBAAkB;iBAoK9B,UAAU,CAAC,EAAE,GAAG,CAAC,CAiB3B;yBAtUsB,CAAC,SAAZ,SAAU;UAEV,MAAM;eACN,CAAC;iBACD,qBAAqB;kBACrB,OAAO;;;;;;;;;;;;;;;;kCA0IR,OAAO,CAAC;IAChB,YAAY,EAAE,OAAO,CAAC;IACtB,kBAAkB,EAAE,kBAAkB,CAAC;CACxC,CAAC;0BA1JsC,iBAAiB;yCAKrB,sBAAsB;wCAD0B,YAAY;+BAAZ,YAAY;2CAAZ,YAAY"}