@agoric/ertp 0.16.3-u13.0 → 0.16.3-u16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/exported.d.ts +37 -0
- package/exported.js +2 -1
- package/package.json +35 -26
- package/src/amountMath.d.ts +44 -31
- package/src/amountMath.d.ts.map +1 -1
- package/src/amountMath.js +130 -120
- package/src/amountStore.d.ts +9 -0
- package/src/amountStore.d.ts.map +1 -0
- package/src/amountStore.js +34 -0
- package/src/displayInfo.d.ts +3 -0
- package/src/displayInfo.d.ts.map +1 -1
- package/src/displayInfo.js +2 -0
- package/src/index.js +8 -0
- package/src/issuerKit.d.ts +30 -6
- package/src/issuerKit.d.ts.map +1 -1
- package/src/issuerKit.js +218 -76
- package/src/legacy-payment-helpers.d.ts +6 -1
- package/src/legacy-payment-helpers.d.ts.map +1 -1
- package/src/legacy-payment-helpers.js +33 -32
- package/src/mathHelpers/copyBagMathHelpers.d.ts +3 -4
- package/src/mathHelpers/copyBagMathHelpers.d.ts.map +1 -1
- package/src/mathHelpers/copyBagMathHelpers.js +4 -5
- package/src/mathHelpers/copySetMathHelpers.d.ts +3 -3
- package/src/mathHelpers/copySetMathHelpers.d.ts.map +1 -1
- package/src/mathHelpers/copySetMathHelpers.js +6 -4
- package/src/mathHelpers/natMathHelpers.d.ts +8 -7
- package/src/mathHelpers/natMathHelpers.d.ts.map +1 -1
- package/src/mathHelpers/natMathHelpers.js +7 -8
- package/src/mathHelpers/setMathHelpers.d.ts +2 -0
- package/src/mathHelpers/setMathHelpers.d.ts.map +1 -1
- package/src/mathHelpers/setMathHelpers.js +2 -1
- package/src/payment.d.ts +4 -2
- package/src/payment.d.ts.map +1 -1
- package/src/payment.js +6 -7
- package/src/paymentLedger.d.ts +6 -2
- package/src/paymentLedger.d.ts.map +1 -1
- package/src/paymentLedger.js +71 -90
- package/src/purse.d.ts +19 -9
- package/src/purse.d.ts.map +1 -1
- package/src/purse.js +86 -25
- package/src/transientNotifier.d.ts +1 -1
- package/src/transientNotifier.d.ts.map +1 -1
- package/src/transientNotifier.js +5 -0
- package/src/typeGuards.d.ts +41 -9
- package/src/typeGuards.d.ts.map +1 -1
- package/src/typeGuards.js +38 -43
- package/src/types.d.ts +250 -215
- package/src/types.d.ts.map +1 -1
- package/src/types.js +305 -326
- package/CHANGELOG.md +0 -767
- package/src/types-ambient.d.ts +0 -376
- package/src/types-ambient.d.ts.map +0 -1
- package/src/types-ambient.js +0 -440
package/src/types.js
CHANGED
|
@@ -1,152 +1,182 @@
|
|
|
1
|
-
export {};
|
|
2
1
|
// @jessie-check
|
|
3
2
|
|
|
4
|
-
|
|
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 */
|
|
5
27
|
|
|
6
28
|
/**
|
|
7
29
|
* @template {AssetKind} [K=AssetKind]
|
|
8
|
-
* @
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
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.
|
|
20
47
|
*/
|
|
21
48
|
|
|
22
49
|
/**
|
|
23
|
-
* @typedef {NatValue | SetValue | CopySet | CopyBag} AmountValue
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* by that key.
|
|
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.
|
|
44
70
|
*/
|
|
45
71
|
|
|
46
72
|
/**
|
|
47
|
-
* @typedef {'nat' | 'set' | 'copySet' | 'copyBag'
|
|
48
|
-
*
|
|
49
|
-
* See doc-comment for `AmountValue`.
|
|
73
|
+
* @typedef {'nat' | 'set' | 'copySet' | 'copyBag'} AssetKind See doc-comment
|
|
74
|
+
* for `AmountValue`.
|
|
50
75
|
*/
|
|
51
76
|
|
|
52
77
|
/**
|
|
53
78
|
* @template {AssetKind} K
|
|
54
|
-
* @
|
|
55
|
-
* K extends '
|
|
56
|
-
*
|
|
57
|
-
* K extends '
|
|
58
|
-
*
|
|
59
|
-
*
|
|
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
|
|
60
89
|
*/
|
|
61
90
|
|
|
62
91
|
/**
|
|
63
92
|
* @template {AmountValue} V
|
|
64
|
-
* @typedef {V extends NatValue
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
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
|
|
69
102
|
*/
|
|
70
103
|
|
|
71
104
|
/**
|
|
72
105
|
* @template {AssetKind} [K=AssetKind]
|
|
73
106
|
* @typedef {object} DisplayInfo
|
|
74
|
-
* @property {number} [decimalPlaces] Tells the display software how
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
* should be used for *display purposes only*. Any other use is an
|
|
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
|
|
83
115
|
* anti-pattern.
|
|
84
|
-
* @property {K} assetKind - the kind of asset, either
|
|
85
|
-
* AssetKind.
|
|
86
|
-
* AssetKind.SET or AssetKind.COPY_SET (non-fungible)
|
|
116
|
+
* @property {K} assetKind - the kind of asset, either AssetKind.NAT (fungible)
|
|
117
|
+
* or AssetKind.SET or AssetKind.COPY_SET (non-fungible)
|
|
87
118
|
*/
|
|
88
119
|
|
|
120
|
+
// XXX hack around JSDoc union handling
|
|
89
121
|
/**
|
|
90
|
-
* @template {AssetKind}
|
|
91
|
-
* @typedef {object}
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
* as 'BTC' or 'moola') is provided by the maker of the issuer and should
|
|
95
|
-
* not be trusted as accurate.
|
|
96
|
-
*
|
|
97
|
-
* Every amount created by a particular AmountMath will share the same brand,
|
|
98
|
-
* but recipients cannot rely on the brand to verify that a purported amount
|
|
99
|
-
* represents the issuer they intended, since the same brand can be reused by
|
|
100
|
-
* a misbehaving issuer.
|
|
101
|
-
*
|
|
102
|
-
* @property {(allegedIssuer: ERef<Issuer>) => Promise<boolean>} isMyIssuer
|
|
103
|
-
* Should be used with `issuer.getBrand` to ensure an issuer and brand match.
|
|
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.
|
|
104
126
|
* @property {() => string} getAllegedName
|
|
105
|
-
* @property {() => DisplayInfo<K>} getDisplayInfo
|
|
106
|
-
*
|
|
127
|
+
* @property {() => DisplayInfo<K>} getDisplayInfo Give information to UI on how
|
|
128
|
+
* to display the amount.
|
|
107
129
|
* @property {() => Pattern} getAmountShape
|
|
108
130
|
*/
|
|
109
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
|
+
|
|
110
145
|
// /////////////////////////// Issuer //////////////////////////////////////////
|
|
111
146
|
|
|
112
147
|
/**
|
|
113
|
-
* @callback IssuerIsLive
|
|
114
|
-
*
|
|
115
|
-
* Return true if the payment continues to exist.
|
|
116
|
-
*
|
|
117
|
-
* If the payment is a promise, the operation will proceed upon
|
|
118
|
-
* resolution.
|
|
148
|
+
* @callback IssuerIsLive Return true if the payment continues to exist.
|
|
119
149
|
*
|
|
150
|
+
* If the payment is a promise, the operation will proceed upon fulfillment.
|
|
120
151
|
* @param {ERef<Payment>} payment
|
|
121
152
|
* @returns {Promise<boolean>}
|
|
122
153
|
*/
|
|
123
154
|
/**
|
|
124
155
|
* @template {AssetKind} K
|
|
125
|
-
* @
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
* @param {ERef<Payment>} payment
|
|
135
|
-
* @returns {Promise<Amount<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>>}
|
|
136
164
|
*/
|
|
137
165
|
|
|
138
166
|
/**
|
|
139
|
-
* @callback IssuerBurn
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
* payment
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
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.
|
|
150
180
|
* @param {ERef<Payment>} payment
|
|
151
181
|
* @param {Pattern} [optAmountShape]
|
|
152
182
|
* @returns {Promise<Amount>}
|
|
@@ -154,146 +184,105 @@ export {};
|
|
|
154
184
|
|
|
155
185
|
/**
|
|
156
186
|
* @template {AssetKind} K
|
|
157
|
-
* @
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
* @
|
|
169
|
-
*
|
|
170
|
-
* @
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
* @
|
|
175
|
-
* @callback IssuerCombine
|
|
176
|
-
*
|
|
177
|
-
* Combine multiple payments into one payment.
|
|
178
|
-
*
|
|
179
|
-
* If any of the payments is a promise, the operation will proceed
|
|
180
|
-
* upon resolution.
|
|
181
|
-
*
|
|
182
|
-
* @param {ERef<Payment<K>>[]} paymentsArray
|
|
183
|
-
* @param {Amount<K>} [optTotalAmount]
|
|
184
|
-
* @returns {Promise<Payment<K>>}
|
|
185
|
-
*/
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* @template {AssetKind} K
|
|
189
|
-
* @callback IssuerSplit
|
|
190
|
-
*
|
|
191
|
-
* Split a single payment into two payments,
|
|
192
|
-
* A and B, according to the paymentAmountA passed in.
|
|
193
|
-
*
|
|
194
|
-
* If the payment is a promise, the operation will proceed upon
|
|
195
|
-
* resolution.
|
|
196
|
-
*
|
|
197
|
-
* @param {ERef<Payment<K>>} payment
|
|
198
|
-
* @param {Amount<K>} paymentAmountA
|
|
199
|
-
* @returns {Promise<Payment<K>[]>}
|
|
200
|
-
*/
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* @callback IssuerSplitMany
|
|
204
|
-
*
|
|
205
|
-
* Split a single payment into many payments, according to the amounts
|
|
206
|
-
* passed in.
|
|
207
|
-
*
|
|
208
|
-
* If the payment is a promise, the operation will proceed upon
|
|
209
|
-
* resolution.
|
|
210
|
-
*
|
|
211
|
-
* @param {ERef<Payment>} payment
|
|
212
|
-
* @param {Amount[]} amounts
|
|
213
|
-
* @returns {Promise<Payment[]>}
|
|
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
|
|
214
205
|
*/
|
|
215
206
|
|
|
216
207
|
/**
|
|
217
208
|
* @template {AssetKind} [K=AssetKind]
|
|
218
|
-
* @
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
* payments,
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
* payment is valid.
|
|
226
|
-
*
|
|
227
|
-
* @property {() => Brand<K>} getBrand Get the Brand for this Issuer. The
|
|
228
|
-
* Brand indicates the type of digital asset and is shared by the
|
|
229
|
-
* mint, the issuer, and any purses and payments of this particular
|
|
230
|
-
* kind. The brand is not closely held, so this function should not be
|
|
231
|
-
* trusted to identify an issuer alone. Fake digital assets and amount
|
|
232
|
-
* can use another issuer's brand.
|
|
233
|
-
*
|
|
234
|
-
* @property {() => string} getAllegedName Get the allegedName for
|
|
235
|
-
* this mint/issuer
|
|
236
|
-
* @property {() => AssetKind} getAssetKind Get the kind of
|
|
237
|
-
* MathHelpers used by this Issuer.
|
|
238
|
-
* @property {() => DisplayInfo<K>} getDisplayInfo Give information to UI
|
|
239
|
-
* on how to display amounts for this issuer.
|
|
240
|
-
* @property {() => Purse<K>} makeEmptyPurse Make an empty purse of this
|
|
241
|
-
* brand.
|
|
242
|
-
* @property {IssuerIsLive} isLive
|
|
243
|
-
* @property {IssuerGetAmountOf<K>} getAmountOf
|
|
244
|
-
* @property {IssuerBurn} burn
|
|
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.
|
|
245
216
|
*/
|
|
246
217
|
|
|
247
218
|
/**
|
|
248
219
|
* @template {AssetKind} [K=AssetKind]
|
|
249
220
|
* @typedef {object} PaymentLedger
|
|
250
221
|
* @property {Mint<K>} mint
|
|
251
|
-
* @property {Purse<K>} mintRecoveryPurse
|
|
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.
|
|
252
225
|
* @property {Issuer<K>} issuer
|
|
253
226
|
* @property {Brand<K>} brand
|
|
254
227
|
*/
|
|
255
228
|
|
|
256
229
|
/**
|
|
257
230
|
* @template {AssetKind} [K=AssetKind]
|
|
231
|
+
* @template {Key} [M=Key] member kind, for Amounts that have member values
|
|
258
232
|
* @typedef {object} IssuerKit
|
|
259
|
-
* @property {Mint<K>} mint
|
|
260
|
-
* @property {Purse<K>} mintRecoveryPurse
|
|
261
|
-
*
|
|
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
|
|
262
238
|
* @property {Brand<K>} brand
|
|
263
239
|
* @property {DisplayInfo} displayInfo
|
|
264
240
|
*/
|
|
265
241
|
|
|
266
242
|
/**
|
|
267
243
|
* @typedef {object} AdditionalDisplayInfo
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
*
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
*
|
|
275
|
-
*
|
|
276
|
-
* assets, should not be specified. The decimalPlaces property
|
|
277
|
-
* should be used for *display purposes only*. Any other use is an
|
|
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
|
|
278
252
|
* anti-pattern.
|
|
279
253
|
* @property {AssetKind} [assetKind]
|
|
280
254
|
*/
|
|
281
255
|
|
|
282
256
|
/**
|
|
283
|
-
* @
|
|
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.
|
|
284
264
|
*/
|
|
285
265
|
|
|
266
|
+
// /////////////////////////// Purse / Payment /////////////////////////////////
|
|
267
|
+
|
|
286
268
|
/**
|
|
287
|
-
*
|
|
288
|
-
*
|
|
289
|
-
*
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
*
|
|
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
|
|
295
282
|
*/
|
|
296
283
|
|
|
284
|
+
// /////////////////////////// Purse / Payment /////////////////////////////////
|
|
285
|
+
|
|
297
286
|
/**
|
|
298
287
|
* @callback DepositFacetReceive
|
|
299
288
|
* @param {Payment} payment
|
|
@@ -303,139 +292,129 @@ export {};
|
|
|
303
292
|
|
|
304
293
|
/**
|
|
305
294
|
* @typedef {object} DepositFacet
|
|
306
|
-
* @property {DepositFacetReceive} receive
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
*
|
|
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.
|
|
310
299
|
*
|
|
311
|
-
*
|
|
300
|
+
* If payment is a promise, throw an error.
|
|
312
301
|
*/
|
|
313
302
|
|
|
314
303
|
/**
|
|
315
|
-
* @template {AssetKind} K
|
|
316
|
-
* @
|
|
317
|
-
* @
|
|
318
|
-
*
|
|
319
|
-
*
|
|
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().
|
|
320
311
|
*/
|
|
321
312
|
|
|
322
313
|
/**
|
|
323
314
|
* @template {AssetKind} [K=AssetKind]
|
|
324
|
-
* @
|
|
325
|
-
*
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
*
|
|
333
|
-
*
|
|
334
|
-
*
|
|
335
|
-
*
|
|
336
|
-
*
|
|
337
|
-
*
|
|
338
|
-
*
|
|
339
|
-
*
|
|
340
|
-
*
|
|
341
|
-
*
|
|
342
|
-
*
|
|
343
|
-
*
|
|
344
|
-
*
|
|
345
|
-
*
|
|
346
|
-
*
|
|
347
|
-
*
|
|
348
|
-
*
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
*
|
|
353
|
-
*
|
|
354
|
-
*
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
*
|
|
358
|
-
*
|
|
359
|
-
*
|
|
360
|
-
*
|
|
361
|
-
*
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
* @property {() => Amount<K>} recoverAll
|
|
365
|
-
* For use in emergencies, such as coming back from a traumatic crash and
|
|
366
|
-
* upgrade. This deposits all the payments in this purse's recovery set
|
|
367
|
-
* into the purse itself, returning the total amount of assets recovered.
|
|
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.
|
|
368
355
|
*/
|
|
369
356
|
|
|
370
357
|
/**
|
|
371
358
|
* @template {AssetKind} [K=AssetKind]
|
|
372
|
-
* @
|
|
373
|
-
*
|
|
374
|
-
*
|
|
375
|
-
*
|
|
376
|
-
* that either a payment has
|
|
377
|
-
* started with, or it is used up
|
|
378
|
-
* payment.
|
|
379
|
-
*
|
|
380
|
-
*
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
*
|
|
384
|
-
*
|
|
385
|
-
*
|
|
386
|
-
*
|
|
387
|
-
*
|
|
388
|
-
* @property {() => Brand<K>} getAllegedBrand
|
|
389
|
-
* Get the allegedBrand, indicating the type of digital asset this
|
|
390
|
-
* payment purports to be, and which issuer to use. Because payments
|
|
391
|
-
* are not trusted, any method calls on payments should be treated
|
|
392
|
-
* with suspicion and verified elsewhere.
|
|
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)`.
|
|
393
374
|
*/
|
|
394
375
|
|
|
395
376
|
/**
|
|
396
|
-
* @template {
|
|
397
|
-
* @typedef {object}
|
|
398
|
-
*
|
|
399
|
-
*
|
|
400
|
-
*
|
|
401
|
-
*
|
|
402
|
-
* values labeled with a brand. AmountMath use mathHelpers to do their value
|
|
403
|
-
* arithmetic, and then brand the results, making a new amount.
|
|
404
|
-
*
|
|
405
|
-
* The MathHelpers are designed to be called only from AmountMath, and so
|
|
406
|
-
* all methods but coerce can assume their inputs are valid. They only
|
|
407
|
-
* need to do output validation, and only when there is a possibility of
|
|
408
|
-
* invalid output.
|
|
409
|
-
*
|
|
410
|
-
* @property {(allegedValue: V) => V} doCoerce
|
|
411
|
-
* Check the kind of this value and throw if it is not the
|
|
412
|
-
* expected kind.
|
|
413
|
-
*
|
|
414
|
-
* @property {() => V} doMakeEmpty
|
|
415
|
-
* Get the representation for the identity element (often 0 or an
|
|
416
|
-
* empty array)
|
|
417
|
-
*
|
|
418
|
-
* @property {(value: V) => boolean} doIsEmpty
|
|
419
|
-
* Is the value the identity element?
|
|
420
|
-
*
|
|
421
|
-
* @property {(left: V, right: V) => boolean} doIsGTE
|
|
422
|
-
* Is the left greater than or equal to the right?
|
|
423
|
-
*
|
|
424
|
-
* @property {(left: V, right: V) => boolean} doIsEqual
|
|
425
|
-
* Does left equal right?
|
|
426
|
-
*
|
|
427
|
-
* @property {(left: V, right: V) => V} doAdd
|
|
428
|
-
* Return the left combined with the right.
|
|
429
|
-
*
|
|
430
|
-
* @property {(left: V, right: V) => V} doSubtract
|
|
431
|
-
* Return what remains after removing the right from the left. If
|
|
432
|
-
* something in the right was not in the left, we throw an error.
|
|
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.
|
|
433
383
|
*/
|
|
434
384
|
|
|
385
|
+
// /////////////////////////// MathHelpers /////////////////////////////////////
|
|
386
|
+
|
|
435
387
|
/**
|
|
436
|
-
* @
|
|
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.
|
|
437
413
|
*/
|
|
438
414
|
|
|
415
|
+
/** @typedef {bigint} NatValue */
|
|
416
|
+
|
|
439
417
|
/**
|
|
440
|
-
* @
|
|
418
|
+
* @template {Key} [K=Key]
|
|
419
|
+
* @typedef {K[]} SetValue
|
|
441
420
|
*/
|