chore(ERTP): additional input validation and clean up
* feat(ERTP): enforce input validation in ERTP/AmountMath
BREAKING CHANGE: NatValues now only accept bigints, lower-case amountMath is removed, and AmountMath methods always follow the order of: brand, value
* chore: fix up INPUT_VALIDATON.md
* chore: address PR comments
MODIFY
index.js
index.js
@@ -17,3 +17,11 @@ export {
sameStructure,
fulfillToStructure,
} from './src/structure.js';
+export {
+ assertRecord,
+ assertCopyArray,
+ assertRemotable,
+ isRemotable,
+ isRecord,
+ isCopyArray,
+} from './src/assertPassStyleOf.js';

ADD
src/assertPassStyleOf.js
+// @ts-check
+
+import { passStyleOf } from './passStyleOf.js';
+
+const { details: X, quote: q } = assert;
+
+/**
+ * @typedef {Array} CopyArray
+ */
+
+/**
+ * @typedef {Record<string, Passable>} CopyRecord
+ */
+
+/**
+ * Check whether the argument is a pass-by-copy array, AKA a "copyArray"
+ * in @agoric/marshal terms
+ *
+ * @param {CopyArray} array
+ * @returns {boolean}
+ */
+const isCopyArray = array => passStyleOf(array) === 'copyArray';
+harden(isCopyArray);
+
+/**
+ * Check whether the argument is a pass-by-copy record, AKA a
+ * "copyRecord" in @agoric/marshal terms
+ *
+ * @param {CopyRecord} record
+ * @returns {boolean}
+ */
+const isRecord = record => passStyleOf(record) === 'copyRecord';
+harden(isRecord);
+
+/**
+ * Check whether the argument is a remotable.
+ *
+ * @param {Remotable} remotable
+ * @returns {boolean}
+ */
+const isRemotable = remotable => passStyleOf(remotable) === 'remotable';
+harden(isRemotable);
+
+/**
+ * Assert that the argument is a pass-by-copy array, AKA a "copyArray"
+ * in @agoric/marshal terms
+ *
+ * @param {CopyArray} array
+ * @param {string=} optNameOfArray
+ * @returns {void}
+ */
+const assertCopyArray = (array, optNameOfArray = 'Alleged array') => {
+ const passStyle = passStyleOf(array);
+ assert(
+ passStyle === 'copyArray',
+ X`${q(
+ optNameOfArray,
+ )} ${array} must be a pass-by-copy array, not ${passStyle}`,
+ );
+};
+harden(assertCopyArray);
+
+/**
+ * Assert that the argument is a pass-by-copy record, or a
+ * "copyRecord" in @agoric/marshal terms
+ *
+ * @param {CopyRecord} record
+ * @param {string=} optNameOfRecord
+ * @returns {void}
+ */
+const assertRecord = (record, optNameOfRecord = 'Alleged record') => {
+ const passStyle = passStyleOf(record);
+ assert(
+ passStyle === 'copyRecord',
+ X`${q(
+ optNameOfRecord,
+ )} ${record} must be a pass-by-copy record, not ${passStyle}`,
+ );
+};
+harden(assertRecord);
+
+/**
+ * Assert that the argument is a remotable.
+ *
+ * @param {Remotable} remotable
+ * @param {string=} optNameOfRemotable
+ * @returns {void}
+ */
+const assertRemotable = (
+ remotable,
+ optNameOfRemotable = 'Alleged remotable',
+) => {
+ const passStyle = passStyleOf(remotable);
+ assert(
+ passStyle === 'remotable',
+ X`${q(
+ optNameOfRemotable,
+ )} ${remotable} must be a remotable, not ${passStyle}`,
+ );
+};
+harden(assertRemotable);
+
+export {
+ assertRecord,
+ assertCopyArray,
+ assertRemotable,
+ isRemotable,
+ isRecord,
+ isCopyArray,
+};

chore(ERTP): additional input validation and clean up (#3892)

* feat(ERTP): enforce input validation in ERTP/AmountMath

BREAKING CHANGE: NatValues now only accept bigints, lower-case amountMath is removed, and AmountMath methods always follow the order of: brand, value

* chore: fix up INPUT_VALIDATON.md

* chore: address PR comments