@@ -13,26 +13,27 @@ import {
13
13
looksLikeBrand ,
14
14
} from './typeGuards' ;
15
15
16
- // We want an enum, but narrowed to the AmountMathKind type.
16
+ // We want an enum, but narrowed to the AssetKind type.
17
17
/**
18
- * Constants for the kinds of amountMath we support.
18
+ * Constants for the kinds of assets we support.
19
19
*
20
20
* @type {{ NAT: 'nat', SET: 'set' } }
21
21
*/
22
- const MathKind = {
22
+ const AssetKind = {
23
23
NAT : 'nat' ,
24
24
SET : 'set' ,
25
25
} ;
26
- harden ( MathKind ) ;
26
+ harden ( AssetKind ) ;
27
27
28
28
/**
29
29
* Amounts describe digital assets. From an amount, you can learn the
30
- * kind of digital asset as well as "how much" or "how many". Amounts
31
- * have two parts: a brand (the kind of digital asset) and the value
32
- * (the answer to "how much"). For example, in the phrase "5 bucks",
33
- * "bucks" takes the role of the brand and the value is 5. Amounts
34
- * can describe fungible and non-fungible digital assets. Amounts are
35
- * pass-by-copy and can be made by and sent to anyone.
30
+ * brand of digital asset as well as "how much" or "how many". Amounts
31
+ * have two parts: a brand (loosely speaking, the type of digital
32
+ * asset) and the value (the answer to "how much"). For example, in
33
+ * the phrase "5 bucks", "bucks" takes the role of the brand and the
34
+ * value is 5. Amounts can describe fungible and non-fungible digital
35
+ * assets. Amounts are pass-by-copy and can be made by and sent to
36
+ * anyone.
36
37
*
37
38
* The issuer has an internal table that maps purses and payments to
38
39
* amounts. The issuer must be able to do things such as add digital
@@ -51,15 +52,16 @@ harden(MathKind);
51
52
*
52
53
* amountMath uses mathHelpers to do most of the work, but then adds
53
54
* the brand to the result. The function `value` gets the value from
54
- * the amount by removing the brand (amount -> value), and the function
55
- * `make` adds the brand to produce an amount (value -> amount). The
56
- * function `coerce` takes an amount and checks it, returning an amount (amount
57
- * -> amount).
55
+ * the amount by removing the brand (amount -> value), and the
56
+ * function `make` adds the brand to produce an amount (value ->
57
+ * amount). The function `coerce` takes an amount and checks it,
58
+ * returning an amount (amount -> amount).
58
59
*
59
- * Each issuer of digital assets has an associated brand in a one-to-one
60
- * mapping. In untrusted contexts, such as in analyzing payments and
61
- * amounts, we can get the brand and find the issuer which matches the
62
- * brand. The issuer and the brand mutually validate each other.
60
+ * Each issuer of digital assets has an associated brand in a
61
+ * one-to-one mapping. In untrusted contexts, such as in analyzing
62
+ * payments and amounts, we can get the brand and find the issuer
63
+ * which matches the brand. The issuer and the brand mutually validate
64
+ * each other.
63
65
*/
64
66
65
67
/** @type {{ nat: NatMathHelpers, set: SetMathHelpers } } */
@@ -82,8 +84,8 @@ const getHelpersFromValue = value => {
82
84
assert . fail ( X `value ${ value } must be a bigint or an array` ) ;
83
85
} ;
84
86
85
- /** @type {(amount: Amount) => AmountMathKind } */
86
- const getMathKind = amount => {
87
+ /** @type {(amount: Amount) => AssetKind } */
88
+ const getAssetKind = amount => {
87
89
if ( looksLikeSetValue ( amount . value ) ) {
88
90
return 'set' ;
89
91
}
@@ -199,16 +201,16 @@ const AmountMath = {
199
201
} ,
200
202
// @ts -ignore TODO Why doesn't this type correctly?
201
203
getValue : ( brand , amount ) => AmountMath . coerce ( brand , amount ) . value ,
202
- makeEmpty : ( brand , mathKind = MathKind . NAT ) => {
204
+ makeEmpty : ( brand , assetKind = AssetKind . NAT ) => {
203
205
assert (
204
- helpers [ mathKind ] ,
205
- X `${ mathKind } must be MathKind .NAT or MathKind .SET` ,
206
+ helpers [ assetKind ] ,
207
+ X `${ assetKind } must be AssetKind .NAT or AssetKind .SET` ,
206
208
) ;
207
209
assertLooksLikeBrand ( brand ) ;
208
- return noCoerceMake ( helpers [ mathKind ] . doMakeEmpty ( ) , brand ) ;
210
+ return noCoerceMake ( helpers [ assetKind ] . doMakeEmpty ( ) , brand ) ;
209
211
} ,
210
212
makeEmptyFromAmount : amount =>
211
- AmountMath . makeEmpty ( amount . brand , getMathKind ( amount ) ) ,
213
+ AmountMath . makeEmpty ( amount . brand , getAssetKind ( amount ) ) ,
212
214
isEmpty : ( amount , brand = undefined ) => {
213
215
assertLooksLikeAmount ( amount ) ;
214
216
optionalBrandCheck ( amount , brand ) ;
@@ -253,4 +255,4 @@ harden(AmountMath);
253
255
*/
254
256
const amountMath = AmountMath ;
255
257
256
- export { amountMath , AmountMath , MathKind , getMathKind } ;
258
+ export { amountMath , AmountMath , AssetKind , getAssetKind } ;
0 commit comments