@agoric/ertp 0.15.6-pismo-dev-0d5327f.0 → 0.16.1-dev-bf4b59f.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.
Files changed (52) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/README.md +1 -1
  3. package/exported.js +1 -1
  4. package/package.json +19 -16
  5. package/src/amountMath.d.ts +53 -0
  6. package/src/amountMath.d.ts.map +1 -0
  7. package/src/amountMath.js +78 -85
  8. package/src/displayInfo.d.ts +2 -0
  9. package/src/displayInfo.d.ts.map +1 -0
  10. package/src/displayInfo.js +6 -10
  11. package/src/index.d.ts +4 -0
  12. package/src/index.d.ts.map +1 -0
  13. package/src/index.js +1 -1
  14. package/src/issuerKit.d.ts +19 -0
  15. package/src/issuerKit.d.ts.map +1 -0
  16. package/src/issuerKit.js +65 -22
  17. package/src/legacy-payment-helpers.d.ts +5 -0
  18. package/src/legacy-payment-helpers.d.ts.map +1 -0
  19. package/src/legacy-payment-helpers.js +146 -0
  20. package/src/mathHelpers/copyBagMathHelpers.d.ts +5 -0
  21. package/src/mathHelpers/copyBagMathHelpers.d.ts.map +1 -0
  22. package/src/mathHelpers/copyBagMathHelpers.js +6 -6
  23. package/src/mathHelpers/copySetMathHelpers.d.ts +5 -0
  24. package/src/mathHelpers/copySetMathHelpers.d.ts.map +1 -0
  25. package/src/mathHelpers/copySetMathHelpers.js +6 -6
  26. package/src/mathHelpers/natMathHelpers.d.ts +14 -0
  27. package/src/mathHelpers/natMathHelpers.d.ts.map +1 -0
  28. package/src/mathHelpers/natMathHelpers.js +7 -7
  29. package/src/mathHelpers/setMathHelpers.d.ts +6 -0
  30. package/src/mathHelpers/setMathHelpers.d.ts.map +1 -0
  31. package/src/mathHelpers/setMathHelpers.js +3 -3
  32. package/src/payment.d.ts +3 -0
  33. package/src/payment.d.ts.map +1 -0
  34. package/src/payment.js +5 -5
  35. package/src/paymentLedger.d.ts +3 -0
  36. package/src/paymentLedger.d.ts.map +1 -0
  37. package/src/paymentLedger.js +76 -163
  38. package/src/purse.d.ts +13 -0
  39. package/src/purse.d.ts.map +1 -0
  40. package/src/purse.js +15 -9
  41. package/src/transientNotifier.d.ts +5 -0
  42. package/src/transientNotifier.d.ts.map +1 -0
  43. package/src/transientNotifier.js +1 -1
  44. package/src/typeGuards.d.ts +42 -0
  45. package/src/typeGuards.d.ts.map +1 -0
  46. package/src/typeGuards.js +25 -22
  47. package/src/types-ambient.d.ts +376 -0
  48. package/src/types-ambient.d.ts.map +1 -0
  49. package/src/types-ambient.js +440 -0
  50. package/src/types.d.ts +376 -0
  51. package/src/types.d.ts.map +1 -0
  52. package/src/types.js +41 -87
package/CHANGELOG.md CHANGED
@@ -3,6 +3,41 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.16.0](https://github.com/Agoric/agoric-sdk/compare/@agoric/ertp@0.15.3...@agoric/ertp@0.16.0) (2023-05-19)
7
+
8
+
9
+ ### ⚠ BREAKING CHANGES
10
+
11
+ * rename 'fit' to 'mustMatch'
12
+
13
+ ### Features
14
+
15
+ * **ERTP:** hasIssuer(baggage) ([a2c0283](https://github.com/Agoric/agoric-sdk/commit/a2c02839fb2a657b896b83c3da3dad0cb4692502))
16
+ * NotifierShape ([1b53522](https://github.com/Agoric/agoric-sdk/commit/1b535224231463a521f42c96d30018812e923f7b))
17
+ * RatioShape ([3efc7de](https://github.com/Agoric/agoric-sdk/commit/3efc7de9f13be002fa4080bb1dc0a05520b0bbf5))
18
+ * **store:** M.splitArray and M.splitRecord ([#6597](https://github.com/Agoric/agoric-sdk/issues/6597)) ([e7427e3](https://github.com/Agoric/agoric-sdk/commit/e7427e386bcbfbe99312b41342b1fa2e722c57c7))
19
+
20
+
21
+ ### Bug Fixes
22
+
23
+ * **ERTP:** `getCurrentAmountNotifier` returns a `LatestTopic` ([735d005](https://github.com/Agoric/agoric-sdk/commit/735d005ec4f4087a4055d48ff1dd1801c9a3d836))
24
+ * collection type param defaults ([7c529b0](https://github.com/Agoric/agoric-sdk/commit/7c529b0c84a6cc76ac81a455b7b3bb8185ecbbfa))
25
+ * incomparables have no min or max ([#6764](https://github.com/Agoric/agoric-sdk/issues/6764)) ([229708b](https://github.com/Agoric/agoric-sdk/commit/229708bcc66afa53dbab929ce1826787942179f7))
26
+ * remove deprecated issuer payment methods ([#7113](https://github.com/Agoric/agoric-sdk/issues/7113)) ([978894a](https://github.com/Agoric/agoric-sdk/commit/978894a87b526efe9c87b2832030b7beee907b31))
27
+ * **zoe:** payments more recoverable ([#7112](https://github.com/Agoric/agoric-sdk/issues/7112)) ([ce7244d](https://github.com/Agoric/agoric-sdk/commit/ce7244d6cf23f57e6de73b5d119e9681456fded7))
28
+ * missing zcfMint options ([753ea03](https://github.com/Agoric/agoric-sdk/commit/753ea03d713f791bebeea82422d659ffc46bca80))
29
+ * prepare for patterns to schematize storage ([#6819](https://github.com/Agoric/agoric-sdk/issues/6819)) ([f0bd3d6](https://github.com/Agoric/agoric-sdk/commit/f0bd3d62c9e480b102fc077997c65d89c0488fa8))
30
+ * rename from FarClass to ExoClass, etc ([#6323](https://github.com/Agoric/agoric-sdk/issues/6323)) ([da96c7c](https://github.com/Agoric/agoric-sdk/commit/da96c7c3c902a5e266baeedf23df02481f2e9c9d))
31
+ * rename vivify to prepare ([#6825](https://github.com/Agoric/agoric-sdk/issues/6825)) ([9261e42](https://github.com/Agoric/agoric-sdk/commit/9261e42e677a3fc31f52defc8fc7ae800f098838))
32
+ * swingset should define these types, not zoe/ERTP ([35a977b](https://github.com/Agoric/agoric-sdk/commit/35a977b2fa3c03bd5292718e318a26e897ff3d04))
33
+
34
+
35
+ ### Miscellaneous Chores
36
+
37
+ * rename 'fit' to 'mustMatch' ([9fa3232](https://github.com/Agoric/agoric-sdk/commit/9fa32324f84bfb85de9e99e0c9ad277b8017b50e)), closes [#6844](https://github.com/Agoric/agoric-sdk/issues/6844)
38
+
39
+
40
+
6
41
  ### [0.15.5](https://github.com/Agoric/agoric-sdk/compare/@agoric/ertp@0.15.4...@agoric/ertp@0.15.5) (2023-02-17)
7
42
 
8
43
  **Note:** Version bump only for package @agoric/ertp
package/README.md CHANGED
@@ -5,7 +5,7 @@ ERTP is Agoric's digital asset standard.
5
5
  ERTP is a uniform way of transferring tokens and other digital
6
6
  assets in JavaScript. All kinds of digital assets can be easily
7
7
  created, but importantly, they can be transferred in exactly the same
8
- ways, with exactly the same security properties.
8
+ ways, with exactly the same security properties.
9
9
 
10
10
  Learn more about [ERTP fundamentals like mints, issuers, purses and payments](https://agoric.com/documentation/ertp/guide/).
11
11
 
package/exported.js CHANGED
@@ -1 +1 @@
1
- import './src/types.js';
1
+ import './src/types-ambient.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/ertp",
3
- "version": "0.15.6-pismo-dev-0d5327f.0+0d5327f",
3
+ "version": "0.16.1-dev-bf4b59f.0+bf4b59f",
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",
@@ -9,6 +9,8 @@
9
9
  },
10
10
  "scripts": {
11
11
  "build": "exit 0",
12
+ "prepack": "echo \"export {}; \" | cat - src/types-ambient.js > src/types.js && tsc --build jsconfig.build.json",
13
+ "postpack": "git clean -f '*.d.ts*' src/types.js",
12
14
  "test": "ava",
13
15
  "test:c8": "c8 $C8_OPTIONS ava",
14
16
  "test:xs": "yarn test:xs-unit && yarn test:xs-worker",
@@ -17,7 +19,7 @@
17
19
  "lint-fix": "yarn lint:eslint --fix",
18
20
  "lint": "run-s --continue-on-error lint:*",
19
21
  "lint:eslint": "eslint .",
20
- "lint:types": "tsc --maxNodeModuleJsDepth 3 -p jsconfig.json"
22
+ "lint:types": "tsc -p jsconfig.json"
21
23
  },
22
24
  "repository": {
23
25
  "type": "git",
@@ -37,21 +39,22 @@
37
39
  },
38
40
  "homepage": "https://github.com/Agoric/agoric-sdk#readme",
39
41
  "dependencies": {
40
- "@agoric/assert": "0.5.2-pismo-dev-0d5327f.0+0d5327f",
41
- "@agoric/nat": "^4.1.0",
42
- "@agoric/notifier": "0.5.2-pismo-dev-0d5327f.0+0d5327f",
43
- "@agoric/store": "0.8.6-pismo-dev-0d5327f.0+0d5327f",
44
- "@agoric/swingset-vat": "0.31.1-pismo-dev-0d5327f.0+0d5327f",
45
- "@agoric/vat-data": "0.4.6-pismo-dev-0d5327f.0+0d5327f",
46
- "@endo/eventual-send": "^0.16.5",
47
- "@endo/far": "^0.2.11",
48
- "@endo/marshal": "^0.7.5",
49
- "@endo/promise-kit": "^0.2.49"
42
+ "@agoric/assert": "0.6.1-dev-bf4b59f.0+bf4b59f",
43
+ "@agoric/notifier": "0.6.1-dev-bf4b59f.0+bf4b59f",
44
+ "@agoric/store": "0.9.1-dev-bf4b59f.0+bf4b59f",
45
+ "@agoric/swingset-vat": "0.32.1-dev-bf4b59f.0+bf4b59f",
46
+ "@agoric/vat-data": "0.5.1-dev-bf4b59f.0+bf4b59f",
47
+ "@endo/eventual-send": "^0.17.2",
48
+ "@endo/far": "^0.2.18",
49
+ "@endo/marshal": "^0.8.5",
50
+ "@endo/nat": "^4.1.27",
51
+ "@endo/promise-kit": "^0.2.56"
50
52
  },
51
53
  "devDependencies": {
52
- "@endo/bundle-source": "^2.3.1",
53
- "@fast-check/ava": "^1.0.1",
54
- "ava": "^4.3.1"
54
+ "@endo/bundle-source": "^2.5.1",
55
+ "@fast-check/ava": "^1.1.3",
56
+ "ava": "^5.2.0",
57
+ "tsd": "^0.28.1"
55
58
  },
56
59
  "files": [
57
60
  "src",
@@ -76,5 +79,5 @@
76
79
  "publishConfig": {
77
80
  "access": "public"
78
81
  },
79
- "gitHead": "0d5327f87310cf523834853b0546d0e217f37009"
82
+ "gitHead": "bf4b59f2128aca73d786429c6ef4a7c9cdfb6700"
80
83
  }
@@ -0,0 +1,53 @@
1
+ export function assertValueGetHelpers<V extends AmountValue>(value: V): MathHelpers<V>;
2
+ export namespace AmountMath {
3
+ export function make<K extends AssetKind>(brand: Brand<K>, allegedValue: AssetValueForKind<K>): Amount<K>;
4
+ export function coerce<K extends AssetKind>(brand: Brand<K>, allegedAmount: Amount<K>): Amount<K>;
5
+ export function getValue<K extends AssetKind>(brand: Brand<K>, amount: Amount<K>): AssetValueForKind<K>;
6
+ export const makeEmpty: {
7
+ (brand: Brand<AssetKind>): Amount<"nat">;
8
+ <K extends AssetKind>(brand: Brand<AssetKind>, assetKind: K): Amount<K>;
9
+ };
10
+ export function makeEmptyFromAmount<K extends AssetKind>(amount: Amount<K>): Amount<K>;
11
+ export function isEmpty(amount: Amount<AssetKind>, brand?: Brand<AssetKind> | undefined): boolean;
12
+ export { isGTE };
13
+ export function isEqual<K extends AssetKind>(leftAmount: Amount<K>, rightAmount: Amount<K>, brand?: Brand<K> | undefined): boolean;
14
+ export function add<K extends AssetKind>(leftAmount: Amount<K>, rightAmount: Amount<K>, brand?: Brand<K> | undefined): Amount<K>;
15
+ export function subtract<K extends AssetKind>(leftAmount: Amount<K>, rightAmount: Amount<K>, brand?: Brand<K> | undefined): Amount<K>;
16
+ export function min<K extends AssetKind>(x: Amount<K>, y: Amount<K>, brand?: Brand<K> | undefined): Amount<K>;
17
+ export function max<K extends AssetKind>(x: Amount<K>, y: Amount<K>, brand?: Brand<K> | undefined): Amount<K>;
18
+ }
19
+ /**
20
+ * Constants for the kinds of assets we support.
21
+ *
22
+ * @type {{ NAT: 'nat', SET: 'set', COPY_SET: 'copySet', COPY_BAG: 'copyBag' }}
23
+ */
24
+ export const AssetKind: {
25
+ NAT: 'nat';
26
+ SET: 'set';
27
+ COPY_SET: 'copySet';
28
+ COPY_BAG: 'copyBag';
29
+ };
30
+ /**
31
+ * @param {Amount} amount
32
+ */
33
+ export function getAssetKind(amount: Amount): AssetKindForValue<V>;
34
+ /**
35
+ * @param {AssetKind} allegedAK
36
+ */
37
+ export function assertAssetKind(allegedAK: AssetKind): void;
38
+ /**
39
+ * Returns true if the leftAmount is greater than or equal to the
40
+ * rightAmount. The notion of "greater than or equal to" depends
41
+ * on the kind of amount, as defined by the MathHelpers. For example,
42
+ * whether rectangle A is greater than rectangle B depends on whether rectangle
43
+ * A includes rectangle B as defined by the logic in MathHelpers.
44
+ *
45
+ * @template {AssetKind} K
46
+ * @param {Amount<K>} leftAmount
47
+ * @param {Amount<K>} rightAmount
48
+ * @param {Brand<K>} [brand]
49
+ * @returns {boolean}
50
+ */
51
+ declare function isGTE<K extends AssetKind>(leftAmount: Amount<K>, rightAmount: Amount<K>, brand?: Brand<K> | undefined): boolean;
52
+ export {};
53
+ //# sourceMappingURL=amountMath.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"amountMath.d.ts","sourceRoot":"","sources":["amountMath.js"],"names":[],"mappings":"AAuHO,uFAEkC;;IAyFjC,0GAKL;IAUO,kGAQP;IASS,wGAAyD;;;;;IAwB9C,uFAOpB;IAQQ,kGAOR;;IAYQ,mIAGR;IAcI,iIAIJ;IAeS,sIAIT;IAUI,8GAMqC;IAUrC,8GAMqC;;AA1W5C;;;;GAIG;AACH,wBAFU;IAAE,GAAG,EAAE,KAAK,CAAC;IAAC,GAAG,EAAE,KAAK,CAAC;IAAC,QAAQ,EAAE,SAAS,CAAC;IAAC,QAAQ,EAAE,SAAS,CAAA;CAAE,CAO3E;AAoWH;;GAEG;AACH,qCAFW,MAAM,wBAOhB;AAzWD;;GAEG;AACH,2CAFW,SAAS,QAKnB;AAgJD;;;;;;;;;;;;GAYG;AACH,0HAFa,OAAO,CAKnB"}
package/src/amountMath.js CHANGED
@@ -1,15 +1,12 @@
1
- // @ts-check
2
-
3
1
  import { passStyleOf, assertRemotable, assertRecord } from '@endo/marshal';
4
2
 
5
- import './types.js';
6
3
  import { M, matches } from '@agoric/store';
7
4
  import { natMathHelpers } from './mathHelpers/natMathHelpers.js';
8
5
  import { setMathHelpers } from './mathHelpers/setMathHelpers.js';
9
6
  import { copySetMathHelpers } from './mathHelpers/copySetMathHelpers.js';
10
7
  import { copyBagMathHelpers } from './mathHelpers/copyBagMathHelpers.js';
11
8
 
12
- const { details: X, quote: q } = assert;
9
+ const { quote: q, Fail } = assert;
13
10
 
14
11
  /**
15
12
  * Constants for the kinds of assets we support.
@@ -24,12 +21,12 @@ const AssetKind = harden({
24
21
  });
25
22
  const assetKindNames = harden(Object.values(AssetKind).sort());
26
23
 
27
- /** @type {AssertAssetKind} */
24
+ /**
25
+ * @param {AssetKind} allegedAK
26
+ */
28
27
  const assertAssetKind = allegedAK => {
29
28
  assetKindNames.includes(allegedAK) ||
30
- assert.fail(
31
- X`The assetKind ${allegedAK} must be one of ${q(assetKindNames)}`,
32
- );
29
+ Fail`The assetKind ${allegedAK} must be one of ${q(assetKindNames)}`;
33
30
  };
34
31
  harden(assertAssetKind);
35
32
 
@@ -72,12 +69,6 @@ harden(assertAssetKind);
72
69
  * each other.
73
70
  */
74
71
 
75
- /** @type {{
76
- * nat: NatMathHelpers,
77
- * set: SetMathHelpers,
78
- * copySet: CopySetMathHelpers,
79
- * copyBag: CopyBagMathHelpers
80
- * }} */
81
72
  const helpers = {
82
73
  nat: natMathHelpers,
83
74
  set: setMathHelpers,
@@ -107,18 +98,17 @@ const assertValueGetAssetKind = value => {
107
98
  // @ts-expect-error cast
108
99
  return 'copyBag';
109
100
  }
110
- assert.fail(
111
- // TODO This isn't quite the right error message, in case valuePassStyle
112
- // is 'tagged'. We would need to distinguish what kind of tagged
113
- // object it is.
114
- // Also, this kind of manual listing is a maintenance hazard we
115
- // (TODO) will encounter when we extend the math helpers further.
116
- X`value ${value} must be a bigint, copySet, copyBag, or an array, not ${passStyle}`,
117
- );
101
+ // TODO This isn't quite the right error message, in case valuePassStyle
102
+ // is 'tagged'. We would need to distinguish what kind of tagged
103
+ // object it is.
104
+ // Also, this kind of manual listing is a maintenance hazard we
105
+ // (TODO) will encounter when we extend the math helpers further.
106
+ throw Fail`value ${value} must be a bigint, copySet, copyBag, or an array, not ${q(
107
+ passStyle,
108
+ )}`;
118
109
  };
119
110
 
120
111
  /**
121
- *
122
112
  * Asserts that value is a valid AmountMath and returns the appropriate helpers.
123
113
  *
124
114
  * Made available only for testing, but it is harmless for other uses.
@@ -135,16 +125,15 @@ export const assertValueGetHelpers = value =>
135
125
  const optionalBrandCheck = (allegedBrand, brand) => {
136
126
  if (brand !== undefined) {
137
127
  assertRemotable(brand, 'brand');
138
- assert.equal(
139
- allegedBrand,
140
- brand,
141
- X`amount's brand ${allegedBrand} did not match expected brand ${brand}`,
142
- );
128
+ allegedBrand === brand ||
129
+ Fail`amount's brand ${q(allegedBrand)} did not match expected brand ${q(
130
+ brand,
131
+ )}`;
143
132
  }
144
133
  };
145
134
 
146
135
  /**
147
- * @template {AssetKind} [K=AssetKind]
136
+ * @template {AssetKind} K
148
137
  * @param {Amount<K>} leftAmount
149
138
  * @param {Amount<K>} rightAmount
150
139
  * @param {Brand<K> | undefined} brand
@@ -159,18 +148,14 @@ const checkLRAndGetHelpers = (leftAmount, rightAmount, brand = undefined) => {
159
148
  assertRemotable(rightBrand, 'rightBrand');
160
149
  optionalBrandCheck(leftBrand, brand);
161
150
  optionalBrandCheck(rightBrand, brand);
162
- assert.equal(
163
- leftBrand,
164
- rightBrand,
165
- X`Brands in left ${leftBrand} and right ${rightBrand} should match but do not`,
166
- );
151
+ leftBrand === rightBrand ||
152
+ Fail`Brands in left ${q(leftBrand)} and right ${q(
153
+ rightBrand,
154
+ )} should match but do not`;
167
155
  const leftHelpers = assertValueGetHelpers(leftValue);
168
156
  const rightHelpers = assertValueGetHelpers(rightValue);
169
- assert.equal(
170
- leftHelpers,
171
- rightHelpers,
172
- X`The left ${leftAmount} and right amount ${rightAmount} had different assetKinds`,
173
- );
157
+ leftHelpers === rightHelpers ||
158
+ Fail`The left ${leftAmount} and right amount ${rightAmount} had different assetKinds`;
174
159
  return leftHelpers;
175
160
  };
176
161
 
@@ -186,6 +171,24 @@ const coerceLR = (h, leftAmount, rightAmount) => {
186
171
  return [h.doCoerce(leftAmount.value), h.doCoerce(rightAmount.value)];
187
172
  };
188
173
 
174
+ /**
175
+ * Returns true if the leftAmount is greater than or equal to the
176
+ * rightAmount. The notion of "greater than or equal to" depends
177
+ * on the kind of amount, as defined by the MathHelpers. For example,
178
+ * whether rectangle A is greater than rectangle B depends on whether rectangle
179
+ * A includes rectangle B as defined by the logic in MathHelpers.
180
+ *
181
+ * @template {AssetKind} K
182
+ * @param {Amount<K>} leftAmount
183
+ * @param {Amount<K>} rightAmount
184
+ * @param {Brand<K>} [brand]
185
+ * @returns {boolean}
186
+ */
187
+ const isGTE = (leftAmount, rightAmount, brand = undefined) => {
188
+ const h = checkLRAndGetHelpers(leftAmount, rightAmount, brand);
189
+ return h.doIsGTE(...coerceLR(h, leftAmount, rightAmount));
190
+ };
191
+
189
192
  /**
190
193
  * Logic for manipulating amounts.
191
194
  *
@@ -199,7 +202,7 @@ const AmountMath = {
199
202
  /**
200
203
  * Make an amount from a value by adding the brand.
201
204
  *
202
- * @template {AssetKind} [K=AssetKind]
205
+ * @template {AssetKind} K
203
206
  * @param {Brand<K>} brand
204
207
  * @param {AssetValueForKind<K>} allegedValue
205
208
  * @returns {Amount<K>}
@@ -215,8 +218,8 @@ const AmountMath = {
215
218
  * Make sure this amount is valid enough, and return a corresponding
216
219
  * valid amount if so.
217
220
  *
218
- * @template {AssetKind} [K=AssetKind]
219
- * @param {Brand} brand
221
+ * @template {AssetKind} K
222
+ * @param {Brand<K>} brand
220
223
  * @param {Amount<K>} allegedAmount
221
224
  * @returns {Amount<K>}
222
225
  */
@@ -225,16 +228,14 @@ const AmountMath = {
225
228
  assertRecord(allegedAmount, 'amount');
226
229
  const { brand: allegedBrand, value: allegedValue } = allegedAmount;
227
230
  brand === allegedBrand ||
228
- assert.fail(
229
- X`The brand in the allegedAmount ${allegedAmount} in 'coerce' didn't match the specified brand ${brand}.`,
230
- );
231
+ Fail`The brand in the allegedAmount ${allegedAmount} in 'coerce' didn't match the specified brand ${brand}.`;
231
232
  // Will throw on inappropriate value
232
233
  return AmountMath.make(brand, allegedValue);
233
234
  },
234
235
  /**
235
236
  * Extract and return the value.
236
237
  *
237
- * @template {AssetKind} [K=AssetKind]
238
+ * @template {AssetKind} K
238
239
  * @param {Brand<K>} brand
239
240
  * @param {Amount<K>} amount
240
241
  * @returns {AssetValueForKind<K>}
@@ -244,18 +245,15 @@ const AmountMath = {
244
245
  * Return the amount representing an empty amount. This is the
245
246
  * identity element for MathHelpers.add and MatHelpers.subtract.
246
247
  *
247
- * @template {AssetKind} [K='nat']
248
- * @param {Brand<K>} brand
249
- * @param {K} [assetKind]
250
- * @returns {Amount<K>}
248
+ * @type {{
249
+ * (brand: Brand): Amount<'nat'>;
250
+ * <K extends AssetKind>(brand: Brand, assetKind: K): Amount<K>;
251
+ * }}
251
252
  */
252
- // @ts-expect-error TS/jsdoc thinks 'nat' can't be assigned to K subclassing AssetKind
253
- // If we were using TypeScript we'd simply overload the function definition for each case.
254
- makeEmpty: (brand, assetKind = 'nat') => {
253
+ makeEmpty: (brand, assetKind = /** @type {const} */ ('nat')) => {
255
254
  assertRemotable(brand, 'brand');
256
255
  assertAssetKind(assetKind);
257
256
  const value = helpers[assetKind].doMakeEmpty();
258
- // @ts-expect-error TS/jsdoc thinks 'nat' can't be assigned to K subclassing AssetKind
259
257
  return harden({ brand, value });
260
258
  },
261
259
  /**
@@ -278,7 +276,7 @@ const AmountMath = {
278
276
  * Return true if the Amount is empty. Otherwise false.
279
277
  *
280
278
  * @param {Amount} amount
281
- * @param {Brand=} brand
279
+ * @param {Brand} [brand]
282
280
  * @returns {boolean}
283
281
  */
284
282
  isEmpty: (amount, brand = undefined) => {
@@ -289,31 +287,15 @@ const AmountMath = {
289
287
  const h = assertValueGetHelpers(value);
290
288
  return h.doIsEmpty(h.doCoerce(value));
291
289
  },
292
- /**
293
- * Returns true if the leftAmount is greater than or equal to the
294
- * rightAmount. For non-scalars, "greater than or equal to" depends
295
- * on the kind of amount, as defined by the MathHelpers. For example,
296
- * whether rectangle A is greater than rectangle B depends on whether rectangle
297
- * A includes rectangle B as defined by the logic in MathHelpers.
298
- *
299
- * @template {AssetKind} [K=AssetKind]
300
- * @param {Amount<K>} leftAmount
301
- * @param {Amount<K>} rightAmount
302
- * @param {Brand<K>=} brand
303
- * @returns {boolean}
304
- */
305
- isGTE: (leftAmount, rightAmount, brand = undefined) => {
306
- const h = checkLRAndGetHelpers(leftAmount, rightAmount, brand);
307
- return h.doIsGTE(...coerceLR(h, leftAmount, rightAmount));
308
- },
290
+ isGTE,
309
291
  /**
310
292
  * Returns true if the leftAmount equals the rightAmount. We assume
311
293
  * that if isGTE is true in both directions, isEqual is also true
312
294
  *
313
- * @template {AssetKind} [K=AssetKind]
295
+ * @template {AssetKind} K
314
296
  * @param {Amount<K>} leftAmount
315
297
  * @param {Amount<K>} rightAmount
316
- * @param {Brand<K>=} brand
298
+ * @param {Brand<K>} [brand]
317
299
  * @returns {boolean}
318
300
  */
319
301
  isEqual: (leftAmount, rightAmount, brand = undefined) => {
@@ -327,10 +309,10 @@ const AmountMath = {
327
309
  * amount, it usually means including all of the elements from both
328
310
  * left and right.
329
311
  *
330
- * @template {AssetKind} [K=AssetKind]
312
+ * @template {AssetKind} K
331
313
  * @param {Amount<K>} leftAmount
332
314
  * @param {Amount<K>} rightAmount
333
- * @param {Brand<K>=} brand
315
+ * @param {Brand<K>} [brand]
334
316
  * @returns {Amount<K>}
335
317
  */
336
318
  add: (leftAmount, rightAmount, brand = undefined) => {
@@ -346,10 +328,10 @@ const AmountMath = {
346
328
  * left amount must include the right amount, this is NOT equivalent
347
329
  * to set subtraction.
348
330
  *
349
- * @template {AssetKind} [K=AssetKind]
331
+ * @template {AssetKind} K
350
332
  * @param {Amount<K>} leftAmount
351
333
  * @param {Amount<K>} rightAmount
352
- * @param {Brand<K>=} brand
334
+ * @param {Brand<K>} [brand]
353
335
  * @returns {Amount<K>}
354
336
  */
355
337
  subtract: (leftAmount, rightAmount, brand = undefined) => {
@@ -360,28 +342,39 @@ const AmountMath = {
360
342
  /**
361
343
  * Returns the min value between x and y using isGTE
362
344
  *
363
- * @template {AssetKind} [K=AssetKind]
345
+ * @template {AssetKind} K
364
346
  * @param {Amount<K>} x
365
347
  * @param {Amount<K>} y
366
- * @param {Brand<K>=} brand
348
+ * @param {Brand<K>} [brand]
367
349
  * @returns {Amount<K>}
368
350
  */
369
- min: (x, y, brand = undefined) => (AmountMath.isGTE(x, y, brand) ? y : x),
351
+ min: (x, y, brand = undefined) =>
352
+ // eslint-disable-next-line no-nested-ternary
353
+ isGTE(x, y, brand)
354
+ ? y
355
+ : isGTE(y, x, brand)
356
+ ? x
357
+ : Fail`${x} and ${y} are incomparable`,
370
358
  /**
371
359
  * Returns the max value between x and y using isGTE
372
360
  *
373
- * @template {AssetKind} [K=AssetKind]
361
+ * @template {AssetKind} K
374
362
  * @param {Amount<K>} x
375
363
  * @param {Amount<K>} y
376
- * @param {Brand<K>=} brand
364
+ * @param {Brand<K>} [brand]
377
365
  * @returns {Amount<K>}
378
366
  */
379
- max: (x, y, brand = undefined) => (AmountMath.isGTE(x, y, brand) ? x : y),
367
+ max: (x, y, brand = undefined) =>
368
+ // eslint-disable-next-line no-nested-ternary
369
+ isGTE(x, y, brand)
370
+ ? x
371
+ : isGTE(y, x)
372
+ ? y
373
+ : Fail`${x} and ${y} are incomparable`,
380
374
  };
381
375
  harden(AmountMath);
382
376
 
383
377
  /**
384
- *
385
378
  * @param {Amount} amount
386
379
  */
387
380
  const getAssetKind = amount => {
@@ -0,0 +1,2 @@
1
+ export function coerceDisplayInfo(allegedDisplayInfo: AdditionalDisplayInfo, assetKind: AssetKind): DisplayInfo;
2
+ //# sourceMappingURL=displayInfo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"displayInfo.d.ts","sourceRoot":"","sources":["displayInfo.js"],"names":[],"mappings":"AAYO,sDAJI,qBAAqB,aACrB,SAAS,GACP,WAAW,CAiBvB"}
@@ -1,7 +1,7 @@
1
- // @ts-check
1
+ // @jessie-check
2
2
 
3
- import { assert, details as X } from '@agoric/assert';
4
- import { fit } from '@agoric/store';
3
+ import { Fail } from '@agoric/assert';
4
+ import { mustMatch } from '@agoric/store';
5
5
 
6
6
  import { DisplayInfoShape } from './typeGuards.js';
7
7
 
@@ -11,21 +11,17 @@ import { DisplayInfoShape } from './typeGuards.js';
11
11
  * @returns {DisplayInfo}
12
12
  */
13
13
  export const coerceDisplayInfo = (allegedDisplayInfo, assetKind) => {
14
- fit(allegedDisplayInfo, DisplayInfoShape, 'displayInfo');
14
+ mustMatch(allegedDisplayInfo, DisplayInfoShape, 'displayInfo');
15
15
 
16
16
  if (allegedDisplayInfo.assetKind !== undefined) {
17
17
  allegedDisplayInfo.assetKind === assetKind ||
18
- assert.fail(
19
- X`displayInfo.assetKind was present (${allegedDisplayInfo.assetKind}) and did not match the assetKind argument (${assetKind})`,
20
- );
18
+ Fail`displayInfo.assetKind was present (${allegedDisplayInfo.assetKind}) and did not match the assetKind argument (${assetKind})`;
21
19
  }
22
20
  const displayInfo = harden({ ...allegedDisplayInfo, assetKind });
23
21
 
24
22
  if (displayInfo.decimalPlaces !== undefined) {
25
23
  Number.isSafeInteger(displayInfo.decimalPlaces) ||
26
- assert.fail(
27
- X`decimalPlaces ${displayInfo.decimalPlaces} is not a safe integer`,
28
- );
24
+ Fail`decimalPlaces ${displayInfo.decimalPlaces} is not a safe integer`;
29
25
  }
30
26
 
31
27
  return displayInfo;
package/src/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from "./amountMath.js";
2
+ export * from "./issuerKit.js";
3
+ export * from "./typeGuards.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":""}
package/src/index.js CHANGED
@@ -1,4 +1,4 @@
1
- // @ts-check
1
+ // @jessie-check
2
2
 
3
3
  export * from './amountMath.js';
4
4
  export * from './issuerKit.js';
@@ -0,0 +1,19 @@
1
+ export function prepareIssuerKit<K extends AssetKind>(issuerBaggage: MapStore<string, unknown>, optShutdownWithFailure?: import("@agoric/swingset-vat").ShutdownWithFailure | undefined): IssuerKit<K>;
2
+ export function hasIssuer(baggage: MapStore<string, unknown>): any;
3
+ export function makeDurableIssuerKit<K extends AssetKind>(issuerBaggage: MapStore<string, unknown>, name: string, assetKind?: K | undefined, displayInfo?: AdditionalDisplayInfo | undefined, optShutdownWithFailure?: import("@agoric/swingset-vat").ShutdownWithFailure | undefined, { elementShape }?: Partial<{
4
+ elementShape: Pattern;
5
+ }> | undefined): IssuerKit<K>;
6
+ export function makeIssuerKit<K extends AssetKind = "nat">(name: string, assetKind?: K | undefined, displayInfo?: AdditionalDisplayInfo | undefined, optShutdownWithFailure?: import("@agoric/swingset-vat").ShutdownWithFailure | undefined, { elementShape }?: Partial<{
7
+ elementShape: Pattern;
8
+ }> | undefined): IssuerKit<K>;
9
+ export type Baggage = import('@agoric/vat-data').Baggage;
10
+ export type IssuerRecord<K extends AssetKind> = {
11
+ name: string;
12
+ assetKind: K;
13
+ displayInfo: AdditionalDisplayInfo;
14
+ elementShape: Pattern;
15
+ };
16
+ export type IssuerOptionsRecord = Partial<{
17
+ elementShape: Pattern;
18
+ }>;
19
+ //# sourceMappingURL=issuerKit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"issuerKit.d.ts","sourceRoot":"","sources":["issuerKit.js"],"names":[],"mappings":"AA2FO,uMAMN;AASM,mEAAsD;AAmCtD,0GAbI,MAAM;kBAnBmB,OAAO;8BA4C1C;AA+BM,iEAbI,MAAM;kBA9DmB,OAAO;8BA0FxC;sBA3LW,OAAO,kBAAkB,EAAE,OAAO;;UAKlC,MAAM;eACN,CAAC;iBACD,qBAAqB;kBACrB,OAAO;;kCAyFR,QAAQ;IAAC,YAAY,EAAE,OAAO,CAAA;CAAC,CAAC"}