@agoric/ertp 0.16.3-dev-97f26d4.0 → 0.16.3-dev-d708d81.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-97f26d4.0+97f26d4",
3
+ "version": "0.16.3-dev-d708d81.0+d708d81",
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/assert": "0.6.1-dev-97f26d4.0+97f26d4",
43
- "@agoric/notifier": "0.6.3-dev-97f26d4.0+97f26d4",
44
- "@agoric/store": "0.9.3-dev-97f26d4.0+97f26d4",
45
- "@agoric/vat-data": "0.5.3-dev-97f26d4.0+97f26d4",
42
+ "@agoric/assert": "0.6.1-dev-d708d81.0+d708d81",
43
+ "@agoric/notifier": "0.6.3-dev-d708d81.0+d708d81",
44
+ "@agoric/store": "0.9.3-dev-d708d81.0+d708d81",
45
+ "@agoric/vat-data": "0.5.3-dev-d708d81.0+d708d81",
46
46
  "@endo/eventual-send": "^0.17.5",
47
47
  "@endo/far": "^0.2.21",
48
48
  "@endo/marshal": "^0.8.8",
@@ -51,7 +51,7 @@
51
51
  "@endo/promise-kit": "^0.2.59"
52
52
  },
53
53
  "devDependencies": {
54
- "@agoric/swingset-vat": "0.32.3-dev-97f26d4.0+97f26d4",
54
+ "@agoric/swingset-vat": "0.32.3-dev-d708d81.0+d708d81",
55
55
  "@endo/bundle-source": "^2.7.0",
56
56
  "@fast-check/ava": "^1.1.5",
57
57
  "ava": "^5.3.0",
@@ -86,5 +86,5 @@
86
86
  "typeCoverage": {
87
87
  "atLeast": 90.37
88
88
  },
89
- "gitHead": "97f26d4e149bd2665f96571edfdae04f1ffec22d"
89
+ "gitHead": "d708d81ab9cee46fe0c2dfa9555cbabd6f6f44f5"
90
90
  }
package/src/issuerKit.js CHANGED
@@ -10,6 +10,8 @@ import { preparePaymentLedger } from './paymentLedger.js';
10
10
 
11
11
  import './types-ambient.js';
12
12
 
13
+ // TODO Why does TypeScript lose the `MapStore` typing of `Baggage` here, even
14
+ // though it knows the correct type at the exporting `@agoric/vat-data`
13
15
  /** @typedef {import('@agoric/vat-data').Baggage} Baggage */
14
16
 
15
17
  /**
@@ -22,6 +24,8 @@ import './types-ambient.js';
22
24
  */
23
25
 
24
26
  /**
27
+ * Used _only_ internally, to make a new issuerKit or to revive an old one.
28
+ *
25
29
  * @template {AssetKind} K
26
30
  * @param {IssuerRecord<K>} issuerRecord
27
31
  * @param {Baggage} issuerBaggage
@@ -78,6 +82,9 @@ harden(setupIssuerKit);
78
82
  const INSTANCE_KEY = 'issuer';
79
83
 
80
84
  /**
85
+ * Used _only_ to upgrade a predecessor issuerKit. Use `makeDurableIssuerKit` to
86
+ * make a new one.
87
+ *
81
88
  * @template {AssetKind} K
82
89
  * @param {Baggage} issuerBaggage
83
90
  * @param {ShutdownWithFailure} [optShutdownWithFailure] If this issuer fails in
@@ -89,26 +96,51 @@ const INSTANCE_KEY = 'issuer';
89
96
  * https://github.com/Agoric/agoric-sdk/issues/3434
90
97
  * @returns {IssuerKit<K>}
91
98
  */
92
- export const prepareIssuerKit = (
99
+ export const upgradeIssuerKit = (
93
100
  issuerBaggage,
94
101
  optShutdownWithFailure = undefined,
95
102
  ) => {
96
103
  const issuerRecord = issuerBaggage.get(INSTANCE_KEY);
97
104
  return setupIssuerKit(issuerRecord, issuerBaggage, optShutdownWithFailure);
98
105
  };
99
- harden(prepareIssuerKit);
106
+ harden(upgradeIssuerKit);
100
107
 
101
108
  /**
102
- * Does baggage already have an issuer from prepareIssuerKit()? That is: does it
103
- * have the relevant keys defined?
109
+ * Confusingly, `prepareIssuerKit` was the original name for `upgradeIssuerKit`,
110
+ * even though it is used only to upgrade a predecessor issuerKit. Use
111
+ * `makeDurableIssuerKit` to make a new one.
112
+ *
113
+ * @deprecated Use `upgradeIssuerKit` instead if that's what you want. Or
114
+ * `reallyPrepareIssuerKit` if you want the behavior that should have been
115
+ * bound to this name.
116
+ */
117
+ export const prepareIssuerKit = upgradeIssuerKit;
118
+
119
+ /**
120
+ * Does baggage already have an issuerKit?
104
121
  *
105
122
  * @param {Baggage} baggage
106
123
  */
107
124
  export const hasIssuer = baggage => baggage.has(INSTANCE_KEY);
108
125
 
109
- /** @typedef {Partial<{ elementShape: Pattern }>} IssuerOptionsRecord */
126
+ /**
127
+ * `elementShape`, may only be present for collection-style amounts. If present,
128
+ * it is a `Pattern` that every element of this issuerKits's amounts must
129
+ * satisfy. For example, the Zoe Invitation issuerKit uses an elementShape
130
+ * describing the invitation details for an individual invitation. An invitation
131
+ * purse or payment has an amount that can only be a set of these. (Though
132
+ * typically, the amount of an invitation payment is a singleton set. Such a
133
+ * payment is often referred to in the singular as "an invitation".)
134
+ *
135
+ * @typedef {Partial<{
136
+ * elementShape: Pattern;
137
+ * }>} IssuerOptionsRecord
138
+ */
110
139
 
111
140
  /**
141
+ * Used _only_ to make a _new_ durable issuer, i.e., the initial incarnation of
142
+ * that issuer.
143
+ *
112
144
  * @template {AssetKind} K The name becomes part of the brand in asset
113
145
  * descriptions. The name is useful for debugging and double-checking
114
146
  * assumptions, but should not be trusted wrt any external namespace. For
@@ -151,6 +183,78 @@ export const makeDurableIssuerKit = (
151
183
  harden(makeDurableIssuerKit);
152
184
 
153
185
  /**
186
+ * What _should_ have been named `prepareIssuerKit`. Used to either revive a
187
+ * predecessor issuerKit, or to make a new durable one if it is absent, and to
188
+ * place it in baggage for the next successor.
189
+ *
190
+ * @template {AssetKind} K The name becomes part of the brand in asset
191
+ * descriptions. The name is useful for debugging and double-checking
192
+ * assumptions, but should not be trusted wrt any external namespace. For
193
+ * example, anyone could create a new issuer kit with name 'BTC', but it is
194
+ * not bitcoin or even related. It is only the name according to that issuer
195
+ * and brand.
196
+ *
197
+ * The assetKind will be used to import a specific mathHelpers from the
198
+ * mathHelpers library. For example, natMathHelpers, the default, is used for
199
+ * basic fungible tokens.
200
+ *
201
+ * `displayInfo` gives information to the UI on how to display the amount.
202
+ * @param {Baggage} issuerBaggage
203
+ * @param {string} name
204
+ * @param {K} [assetKind]
205
+ * @param {AdditionalDisplayInfo} [displayInfo]
206
+ * @param {ShutdownWithFailure} [optShutdownWithFailure] If this issuer fails in
207
+ * the middle of an atomic action (which btw should never happen), it
208
+ * potentially leaves its ledger in a corrupted state. If this function was
209
+ * provided, then the failed atomic action will call it, so that some larger
210
+ * unit of computation, like the enclosing vat, can be shutdown before
211
+ * anything else is corrupted by that corrupted state. See
212
+ * https://github.com/Agoric/agoric-sdk/issues/3434
213
+ * @param {IssuerOptionsRecord} [options]
214
+ * @returns {IssuerKit<K>}
215
+ */
216
+ export const reallyPrepareIssuerKit = (
217
+ issuerBaggage,
218
+ name,
219
+ // @ts-expect-error K could be instantiated with a different subtype of AssetKind
220
+ assetKind = AssetKind.NAT,
221
+ displayInfo = harden({}),
222
+ optShutdownWithFailure = undefined,
223
+ options = {},
224
+ ) => {
225
+ if (hasIssuer(issuerBaggage)) {
226
+ const { elementShape: _ = undefined } = options;
227
+ const issuerKit = upgradeIssuerKit(issuerBaggage, optShutdownWithFailure);
228
+
229
+ // TODO check consistency with name, assetKind, displayInfo, elementShape.
230
+ // Consistency either means that these are the same, or that they differ
231
+ // in a direction we are prepared to upgrade.
232
+
233
+ // @ts-expect-error Type parameter confusion.
234
+ return issuerKit;
235
+ } else {
236
+ const issuerKit = makeDurableIssuerKit(
237
+ issuerBaggage,
238
+ name,
239
+ assetKind,
240
+ displayInfo,
241
+ optShutdownWithFailure,
242
+ options,
243
+ );
244
+ return issuerKit;
245
+ }
246
+ };
247
+ harden(reallyPrepareIssuerKit);
248
+
249
+ /**
250
+ * Used _only_ to make a new issuerKit that is effectively non-durable. This is
251
+ * currently done by making a durable one in a baggage not reachable from
252
+ * anywhere. TODO Once rebuilt on zones, this should instead just build on the
253
+ * virtual zone. See https://github.com/Agoric/agoric-sdk/pull/7116
254
+ *
255
+ * Currently used for testing only. Should probably continue to be used for
256
+ * testing only.
257
+ *
154
258
  * @template {AssetKind} [K='nat'] The name becomes part of the brand in asset
155
259
  * descriptions. The name is useful for debugging and double-checking
156
260
  * assumptions, but should not be trusted wrt any external namespace. For
@@ -310,6 +310,8 @@ export const preparePaymentLedger = (
310
310
  return payment;
311
311
  };
312
312
 
313
+ /** @type {() => Purse<K>} */
314
+ // @ts-expect-error type parameter confusion
313
315
  const makeEmptyPurse = preparePurseKind(
314
316
  issuerBaggage,
315
317
  name,
package/src/purse.js CHANGED
@@ -3,8 +3,26 @@ import { prepareExoClassKit, makeScalarBigSetStore } from '@agoric/vat-data';
3
3
  import { AmountMath } from './amountMath.js';
4
4
  import { makeTransientNotifierKit } from './transientNotifier.js';
5
5
 
6
+ // TODO `InterfaceGuard` type parameter
7
+ /** @typedef {import('@endo/patterns').InterfaceGuard} InterfaceGuard */
8
+ /** @typedef {import('@agoric/vat-data').Baggage} Baggage */
9
+
6
10
  const { Fail } = assert;
7
11
 
12
+ /**
13
+ * @param {Baggage} issuerBaggage
14
+ * @param {string} name
15
+ * @param {AssetKind} assetKind
16
+ * @param {Brand} brand
17
+ * @param {{
18
+ * purse: InterfaceGuard;
19
+ * depositFacet: InterfaceGuard;
20
+ * }} PurseIKit
21
+ * @param {{
22
+ * depositInternal: any;
23
+ * withdrawInternal: any;
24
+ * }} purseMethods
25
+ */
8
26
  export const preparePurseKind = (
9
27
  issuerBaggage,
10
28
  name,
@@ -115,7 +115,7 @@
115
115
  /**
116
116
  * @callback IssuerIsLive Return true if the payment continues to exist.
117
117
  *
118
- * If the payment is a promise, the operation will proceed upon resolution.
118
+ * If the payment is a promise, the operation will proceed upon fulfillment.
119
119
  * @param {ERef<Payment>} payment
120
120
  * @returns {Promise<boolean>}
121
121
  */
@@ -125,18 +125,25 @@
125
125
  * Because the payment is not trusted, we cannot call a method on it directly,
126
126
  * and must use the issuer instead.
127
127
  *
128
- * If the payment is a promise, the operation will proceed upon resolution.
128
+ * If the payment is a promise, the operation will proceed upon fulfillment.
129
129
  * @param {ERef<Payment>} payment
130
130
  * @returns {Promise<Amount<K>>}
131
131
  */
132
132
 
133
133
  /**
134
134
  * @callback IssuerBurn Burn all of the digital assets in the payment.
135
- * `optAmount` is optional. If `optAmount` is present, the code will insist
136
- * that the amount of the digital assets in the payment is equal to
137
- * `optAmount`, to prevent sending the wrong payment and other confusion.
135
+ * `optAmountShape` is optional. If the `optAmountShape` pattern is present,
136
+ * the amount of the digital assets in the payment must match
137
+ * `optAmountShape`, to prevent sending the wrong payment and other
138
+ * confusion.
138
139
  *
139
- * If the payment is a promise, the operation will proceed upon resolution.
140
+ * If the payment is a promise, the operation will proceed upon fulfillment.
141
+ *
142
+ * As always with optional `Pattern` arguments, keep in mind that technically
143
+ * the value `undefined` itself is a valid `Key` and therefore a valid
144
+ * `Pattern`. But in optional pattern position, a top level `undefined` will
145
+ * be interpreted as absence. If you want to express a `Pattern` that will
146
+ * match only `undefined`, use `M.undefined()` instead.
140
147
  * @param {ERef<Payment>} payment
141
148
  * @param {Pattern} [optAmountShape]
142
149
  * @returns {Promise<Amount>}
@@ -171,7 +178,8 @@
171
178
  * @template {AssetKind} [K=AssetKind]
172
179
  * @typedef {object} PaymentLedger
173
180
  * @property {Mint<K>} mint
174
- * @property {Purse<K>} mintRecoveryPurse
181
+ * @property {Purse<K>} mintRecoveryPurse Useful only to get the recovery set
182
+ * associated with minted payments that are still live.
175
183
  * @property {Issuer<K>} issuer
176
184
  * @property {Brand<K>} brand
177
185
  */
@@ -180,7 +188,8 @@
180
188
  * @template {AssetKind} [K=AssetKind]
181
189
  * @typedef {object} IssuerKit
182
190
  * @property {Mint<K>} mint
183
- * @property {Purse<K>} mintRecoveryPurse
191
+ * @property {Purse<K>} mintRecoveryPurse Useful only to get the recovery set
192
+ * associated with minted payments that are still live.
184
193
  * @property {Issuer<K>} issuer
185
194
  * @property {Brand<K>} brand
186
195
  * @property {DisplayInfo} displayInfo
@@ -211,6 +220,8 @@
211
220
  * Payment containing newly minted amount.
212
221
  */
213
222
 
223
+ // /////////////////////////// Purse / Payment /////////////////////////////////
224
+
214
225
  /**
215
226
  * @callback DepositFacetReceive
216
227
  * @param {Payment} payment
@@ -298,6 +309,8 @@
298
309
  * be treated with suspicion and verified elsewhere.
299
310
  */
300
311
 
312
+ // /////////////////////////// MathHelpers /////////////////////////////////////
313
+
301
314
  /**
302
315
  * @template {AmountValue} V
303
316
  * @typedef {object} MathHelpers All of the difference in how digital asset
package/src/types.js CHANGED
@@ -116,7 +116,7 @@ export {};
116
116
  /**
117
117
  * @callback IssuerIsLive Return true if the payment continues to exist.
118
118
  *
119
- * If the payment is a promise, the operation will proceed upon resolution.
119
+ * If the payment is a promise, the operation will proceed upon fulfillment.
120
120
  * @param {ERef<Payment>} payment
121
121
  * @returns {Promise<boolean>}
122
122
  */
@@ -126,18 +126,25 @@ export {};
126
126
  * Because the payment is not trusted, we cannot call a method on it directly,
127
127
  * and must use the issuer instead.
128
128
  *
129
- * If the payment is a promise, the operation will proceed upon resolution.
129
+ * If the payment is a promise, the operation will proceed upon fulfillment.
130
130
  * @param {ERef<Payment>} payment
131
131
  * @returns {Promise<Amount<K>>}
132
132
  */
133
133
 
134
134
  /**
135
135
  * @callback IssuerBurn Burn all of the digital assets in the payment.
136
- * `optAmount` is optional. If `optAmount` is present, the code will insist
137
- * that the amount of the digital assets in the payment is equal to
138
- * `optAmount`, to prevent sending the wrong payment and other confusion.
136
+ * `optAmountShape` is optional. If the `optAmountShape` pattern is present,
137
+ * the amount of the digital assets in the payment must match
138
+ * `optAmountShape`, to prevent sending the wrong payment and other
139
+ * confusion.
139
140
  *
140
- * If the payment is a promise, the operation will proceed upon resolution.
141
+ * If the payment is a promise, the operation will proceed upon fulfillment.
142
+ *
143
+ * As always with optional `Pattern` arguments, keep in mind that technically
144
+ * the value `undefined` itself is a valid `Key` and therefore a valid
145
+ * `Pattern`. But in optional pattern position, a top level `undefined` will
146
+ * be interpreted as absence. If you want to express a `Pattern` that will
147
+ * match only `undefined`, use `M.undefined()` instead.
141
148
  * @param {ERef<Payment>} payment
142
149
  * @param {Pattern} [optAmountShape]
143
150
  * @returns {Promise<Amount>}
@@ -172,7 +179,8 @@ export {};
172
179
  * @template {AssetKind} [K=AssetKind]
173
180
  * @typedef {object} PaymentLedger
174
181
  * @property {Mint<K>} mint
175
- * @property {Purse<K>} mintRecoveryPurse
182
+ * @property {Purse<K>} mintRecoveryPurse Useful only to get the recovery set
183
+ * associated with minted payments that are still live.
176
184
  * @property {Issuer<K>} issuer
177
185
  * @property {Brand<K>} brand
178
186
  */
@@ -181,7 +189,8 @@ export {};
181
189
  * @template {AssetKind} [K=AssetKind]
182
190
  * @typedef {object} IssuerKit
183
191
  * @property {Mint<K>} mint
184
- * @property {Purse<K>} mintRecoveryPurse
192
+ * @property {Purse<K>} mintRecoveryPurse Useful only to get the recovery set
193
+ * associated with minted payments that are still live.
185
194
  * @property {Issuer<K>} issuer
186
195
  * @property {Brand<K>} brand
187
196
  * @property {DisplayInfo} displayInfo
@@ -212,6 +221,8 @@ export {};
212
221
  * Payment containing newly minted amount.
213
222
  */
214
223
 
224
+ // /////////////////////////// Purse / Payment /////////////////////////////////
225
+
215
226
  /**
216
227
  * @callback DepositFacetReceive
217
228
  * @param {Payment} payment
@@ -299,6 +310,8 @@ export {};
299
310
  * be treated with suspicion and verified elsewhere.
300
311
  */
301
312
 
313
+ // /////////////////////////// MathHelpers /////////////////////////////////////
314
+
302
315
  /**
303
316
  * @template {AmountValue} V
304
317
  * @typedef {object} MathHelpers All of the difference in how digital asset