@wishknish/knishio-client-ts 0.9.3 → 0.9.4
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/dist/index.cjs +144 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.iife.js +154 -10
- package/dist/index.iife.js.map +1 -1
- package/dist/index.js +144 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/libraries/CheckMolecule.ts +194 -4
package/dist/index.cjs
CHANGED
|
@@ -4493,7 +4493,7 @@ var CheckMolecule = class _CheckMolecule {
|
|
|
4493
4493
|
* @return True if all validations pass
|
|
4494
4494
|
*/
|
|
4495
4495
|
verify(senderWallet) {
|
|
4496
|
-
return this.molecularHash() && this.ots() && this.batchId() && this.continuId() && this.isotopeM() && this.isotopeT() && this.isotopeC() && this.isotopeU() && this.isotopeI() && this.isotopeR() && this.isotopeV(senderWallet || null);
|
|
4496
|
+
return this.molecularHash() && this.ots() && this.batchId() && this.continuId() && this.isotopeM() && this.isotopeT() && this.isotopeC() && this.isotopeU() && this.isotopeI() && this.isotopeR() && this.isotopeP() && this.isotopeA() && this.isotopeB() && this.isotopeF() && this.isotopeV(senderWallet || null);
|
|
4497
4497
|
}
|
|
4498
4498
|
/**
|
|
4499
4499
|
* Validate ContinuID requirement
|
|
@@ -4681,6 +4681,141 @@ var CheckMolecule = class _CheckMolecule {
|
|
|
4681
4681
|
}
|
|
4682
4682
|
return true;
|
|
4683
4683
|
}
|
|
4684
|
+
/**
|
|
4685
|
+
* Validate isotope P atoms (peering)
|
|
4686
|
+
* @return True if valid
|
|
4687
|
+
* @throws WrongTokenTypeException if the token slug is not USER
|
|
4688
|
+
* @throws MetaMissingException if the required peerHost meta field is absent
|
|
4689
|
+
*/
|
|
4690
|
+
isotopeP() {
|
|
4691
|
+
for (const atom of this.molecule.getIsotopes("P")) {
|
|
4692
|
+
if (atom.token !== "USER") {
|
|
4693
|
+
throw new WrongTokenTypeException(`Check::isotopeP() - "${atom.token}" is not a valid Token slug for "${atom.isotope}" isotope Atoms!`);
|
|
4694
|
+
}
|
|
4695
|
+
const metas = atom.aggregatedMeta();
|
|
4696
|
+
if (!Object.prototype.hasOwnProperty.call(metas, "peerHost") || !metas.peerHost) {
|
|
4697
|
+
throw new MetaMissingException('Check::isotopeP() - Required meta field "peerHost" is missing!');
|
|
4698
|
+
}
|
|
4699
|
+
}
|
|
4700
|
+
return true;
|
|
4701
|
+
}
|
|
4702
|
+
/**
|
|
4703
|
+
* Validate isotope A atoms (append request)
|
|
4704
|
+
* @return True if valid
|
|
4705
|
+
* @throws WrongTokenTypeException if the token slug is not USER
|
|
4706
|
+
* @throws MetaMissingException if metaType, metaId or the action meta field is absent
|
|
4707
|
+
*/
|
|
4708
|
+
isotopeA() {
|
|
4709
|
+
for (const atom of this.molecule.getIsotopes("A")) {
|
|
4710
|
+
if (atom.token !== "USER") {
|
|
4711
|
+
throw new WrongTokenTypeException(`Check::isotopeA() - "${atom.token}" is not a valid Token slug for "${atom.isotope}" isotope Atoms!`);
|
|
4712
|
+
}
|
|
4713
|
+
if (!atom.metaType) {
|
|
4714
|
+
throw new MetaMissingException('Check::isotopeA() - Required field "metaType" is missing!');
|
|
4715
|
+
}
|
|
4716
|
+
if (!atom.metaId) {
|
|
4717
|
+
throw new MetaMissingException('Check::isotopeA() - Required field "metaId" is missing!');
|
|
4718
|
+
}
|
|
4719
|
+
const metas = atom.aggregatedMeta();
|
|
4720
|
+
if (!Object.prototype.hasOwnProperty.call(metas, "action") || !metas.action) {
|
|
4721
|
+
throw new MetaMissingException('Check::isotopeA() - Required meta field "action" is missing!');
|
|
4722
|
+
}
|
|
4723
|
+
}
|
|
4724
|
+
return true;
|
|
4725
|
+
}
|
|
4726
|
+
/**
|
|
4727
|
+
* Validate isotope B atoms (buffer/exchange)
|
|
4728
|
+
*
|
|
4729
|
+
* Buffer molecules are cross-isotope: their V atoms do not balance on their own
|
|
4730
|
+
* because a B atom absorbs the difference. isotopeV() therefore skips its V-only
|
|
4731
|
+
* conservation checks whenever B (or F) atoms are present, and conservation is
|
|
4732
|
+
* enforced here instead over the combined V+B set.
|
|
4733
|
+
*
|
|
4734
|
+
* @return True if valid
|
|
4735
|
+
* @throws MetaMissingException if metaType is not walletBundle, or metaId is absent
|
|
4736
|
+
* @throws TransferMalformedException if a B atom value is not a number
|
|
4737
|
+
* @throws TransferUnbalancedException if V+B atom values do not sum to zero
|
|
4738
|
+
*/
|
|
4739
|
+
isotopeB() {
|
|
4740
|
+
const isotopeB = this.molecule.getIsotopes("B");
|
|
4741
|
+
if (isotopeB.length === 0) {
|
|
4742
|
+
return true;
|
|
4743
|
+
}
|
|
4744
|
+
for (const atom of isotopeB) {
|
|
4745
|
+
if (!atom.metaType || atom.metaType !== "walletBundle") {
|
|
4746
|
+
throw new MetaMissingException('Check::isotopeB() - B-isotope atoms must have metaType "walletBundle"!');
|
|
4747
|
+
}
|
|
4748
|
+
if (!atom.metaId) {
|
|
4749
|
+
throw new MetaMissingException("Check::isotopeB() - B-isotope atoms must have a metaId!");
|
|
4750
|
+
}
|
|
4751
|
+
const value = atom.value !== null ? Number(atom.value) : Number.NaN;
|
|
4752
|
+
if (Number.isNaN(value)) {
|
|
4753
|
+
throw new TransferMalformedException("Check::isotopeB() - B-isotope atom value is not a valid number!");
|
|
4754
|
+
}
|
|
4755
|
+
}
|
|
4756
|
+
const vAtoms = this.molecule.getIsotopes("V");
|
|
4757
|
+
if (vAtoms.length > 0) {
|
|
4758
|
+
let sum = 0;
|
|
4759
|
+
for (const atom of [...vAtoms, ...isotopeB]) {
|
|
4760
|
+
const value = atom.value !== null ? Number(atom.value) : Number.NaN;
|
|
4761
|
+
if (!Number.isNaN(value)) {
|
|
4762
|
+
sum += value;
|
|
4763
|
+
}
|
|
4764
|
+
}
|
|
4765
|
+
if (sum !== 0) {
|
|
4766
|
+
throw new TransferUnbalancedException("Check::isotopeB() - V+B atom values do not balance to zero!");
|
|
4767
|
+
}
|
|
4768
|
+
}
|
|
4769
|
+
return true;
|
|
4770
|
+
}
|
|
4771
|
+
/**
|
|
4772
|
+
* Validate isotope F atoms (fusion/NFT)
|
|
4773
|
+
*
|
|
4774
|
+
* Mirrors isotopeB() and additionally forbids negative values. Must stay paired
|
|
4775
|
+
* with the hasCrossIsotope gate in isotopeV(), which is keyed on B *or* F: without
|
|
4776
|
+
* this check an F-isotope molecule would skip V-only conservation with nothing
|
|
4777
|
+
* validating V+F conservation in its place.
|
|
4778
|
+
*
|
|
4779
|
+
* @return True if valid
|
|
4780
|
+
* @throws MetaMissingException if metaType is not walletBundle, or metaId is absent
|
|
4781
|
+
* @throws TransferMalformedException if an F atom value is not a number, or is negative
|
|
4782
|
+
* @throws TransferUnbalancedException if V+F atom values do not sum to zero
|
|
4783
|
+
*/
|
|
4784
|
+
isotopeF() {
|
|
4785
|
+
const isotopeF = this.molecule.getIsotopes("F");
|
|
4786
|
+
if (isotopeF.length === 0) {
|
|
4787
|
+
return true;
|
|
4788
|
+
}
|
|
4789
|
+
for (const atom of isotopeF) {
|
|
4790
|
+
if (!atom.metaType || atom.metaType !== "walletBundle") {
|
|
4791
|
+
throw new MetaMissingException('Check::isotopeF() - F-isotope atoms must have metaType "walletBundle"!');
|
|
4792
|
+
}
|
|
4793
|
+
if (!atom.metaId) {
|
|
4794
|
+
throw new MetaMissingException("Check::isotopeF() - F-isotope atoms must have a metaId!");
|
|
4795
|
+
}
|
|
4796
|
+
const value = atom.value !== null ? Number(atom.value) : Number.NaN;
|
|
4797
|
+
if (Number.isNaN(value)) {
|
|
4798
|
+
throw new TransferMalformedException("Check::isotopeF() - F-isotope atom value is not a valid number!");
|
|
4799
|
+
}
|
|
4800
|
+
if (value < 0) {
|
|
4801
|
+
throw new TransferMalformedException("Check::isotopeF() - F-isotope atom value must not be negative!");
|
|
4802
|
+
}
|
|
4803
|
+
}
|
|
4804
|
+
const vAtoms = this.molecule.getIsotopes("V");
|
|
4805
|
+
if (vAtoms.length > 0) {
|
|
4806
|
+
let sum = 0;
|
|
4807
|
+
for (const atom of [...vAtoms, ...isotopeF]) {
|
|
4808
|
+
const value = atom.value !== null ? Number(atom.value) : Number.NaN;
|
|
4809
|
+
if (!Number.isNaN(value)) {
|
|
4810
|
+
sum += value;
|
|
4811
|
+
}
|
|
4812
|
+
}
|
|
4813
|
+
if (sum !== 0) {
|
|
4814
|
+
throw new TransferUnbalancedException("Check::isotopeF() - V+F atom values do not balance to zero!");
|
|
4815
|
+
}
|
|
4816
|
+
}
|
|
4817
|
+
return true;
|
|
4818
|
+
}
|
|
4684
4819
|
/**
|
|
4685
4820
|
* Validate isotope V atoms (value transfers)
|
|
4686
4821
|
* @param senderWallet - Optional wallet for balance validation
|
|
@@ -4692,11 +4827,12 @@ var CheckMolecule = class _CheckMolecule {
|
|
|
4692
4827
|
if (isotopeV.length === 0) {
|
|
4693
4828
|
return true;
|
|
4694
4829
|
}
|
|
4830
|
+
const hasCrossIsotope = this.molecule.getIsotopes("B").length > 0 || this.molecule.getIsotopes("F").length > 0;
|
|
4695
4831
|
const firstAtom = this.molecule.atoms[0];
|
|
4696
4832
|
if (!firstAtom) {
|
|
4697
4833
|
throw new exports.AtomsMissingException("Check::isotopeV() - Missing first atom");
|
|
4698
4834
|
}
|
|
4699
|
-
if (firstAtom.isotope === "V" && isotopeV.length === 2) {
|
|
4835
|
+
if (!hasCrossIsotope && firstAtom.isotope === "V" && isotopeV.length === 2) {
|
|
4700
4836
|
const endAtom = isotopeV[isotopeV.length - 1];
|
|
4701
4837
|
if (!endAtom) {
|
|
4702
4838
|
throw new exports.AtomsMissingException("Check::isotopeV() - Missing end atom");
|
|
@@ -4708,6 +4844,10 @@ var CheckMolecule = class _CheckMolecule {
|
|
|
4708
4844
|
if (endValue < 0) {
|
|
4709
4845
|
throw new TransferMalformedException();
|
|
4710
4846
|
}
|
|
4847
|
+
const firstValueForPair = firstAtom.value !== null ? Number(firstAtom.value) : 0;
|
|
4848
|
+
if (firstValueForPair + endValue !== 0) {
|
|
4849
|
+
throw new TransferUnbalancedException();
|
|
4850
|
+
}
|
|
4711
4851
|
return true;
|
|
4712
4852
|
}
|
|
4713
4853
|
let sum = 0;
|
|
@@ -4736,7 +4876,7 @@ var CheckMolecule = class _CheckMolecule {
|
|
|
4736
4876
|
sum += value;
|
|
4737
4877
|
}
|
|
4738
4878
|
}
|
|
4739
|
-
if (sum !== 0) {
|
|
4879
|
+
if (!hasCrossIsotope && sum !== 0) {
|
|
4740
4880
|
throw new TransferUnbalancedException();
|
|
4741
4881
|
}
|
|
4742
4882
|
if (senderWallet) {
|
|
@@ -4748,7 +4888,7 @@ var CheckMolecule = class _CheckMolecule {
|
|
|
4748
4888
|
if (remainder < 0) {
|
|
4749
4889
|
throw new exports.TransferBalanceException();
|
|
4750
4890
|
}
|
|
4751
|
-
if (remainder !== sum) {
|
|
4891
|
+
if (!hasCrossIsotope && remainder !== sum) {
|
|
4752
4892
|
throw new TransferRemainderException();
|
|
4753
4893
|
}
|
|
4754
4894
|
} else if (sum !== 0) {
|