@agoric/ertp 0.16.3-dev-7940ef4.0 → 0.16.3-dev-b232bfe.0

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