@agoric/ertp 0.16.3-other-dev-8f8782b.0 → 0.16.3-other-dev-fbe72e7.0.fbe72e7

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