@xyo-network/payment-payload-plugins 2.91.5 → 2.91.7
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/browser/Escrow/index.d.cts +1 -0
- package/dist/browser/Escrow/index.d.cts.map +1 -1
- package/dist/browser/Escrow/index.d.mts +1 -0
- package/dist/browser/Escrow/index.d.mts.map +1 -1
- package/dist/browser/Escrow/index.d.ts +1 -0
- package/dist/browser/Escrow/index.d.ts.map +1 -1
- package/dist/browser/Escrow/validators/common/ModuleInstanceValidators/index.d.cts +2 -0
- package/dist/browser/Escrow/validators/common/ModuleInstanceValidators/index.d.cts.map +1 -0
- package/dist/browser/Escrow/validators/common/ModuleInstanceValidators/index.d.mts +2 -0
- package/dist/browser/Escrow/validators/common/ModuleInstanceValidators/index.d.mts.map +1 -0
- package/dist/browser/Escrow/validators/common/ModuleInstanceValidators/index.d.ts +2 -0
- package/dist/browser/Escrow/validators/common/ModuleInstanceValidators/index.d.ts.map +1 -0
- package/dist/browser/Escrow/validators/common/ModuleInstanceValidators/moduleInstanceValidators.d.cts +22 -0
- package/dist/browser/Escrow/validators/common/ModuleInstanceValidators/moduleInstanceValidators.d.cts.map +1 -0
- package/dist/browser/Escrow/validators/common/ModuleInstanceValidators/moduleInstanceValidators.d.mts +22 -0
- package/dist/browser/Escrow/validators/common/ModuleInstanceValidators/moduleInstanceValidators.d.mts.map +1 -0
- package/dist/browser/Escrow/validators/common/ModuleInstanceValidators/moduleInstanceValidators.d.ts +22 -0
- package/dist/browser/Escrow/validators/common/ModuleInstanceValidators/moduleInstanceValidators.d.ts.map +1 -0
- package/dist/browser/Escrow/validators/common/TemporalValidators/index.d.cts +2 -0
- package/dist/browser/Escrow/validators/common/TemporalValidators/index.d.cts.map +1 -0
- package/dist/browser/Escrow/validators/common/TemporalValidators/index.d.mts +2 -0
- package/dist/browser/Escrow/validators/common/TemporalValidators/index.d.mts.map +1 -0
- package/dist/browser/Escrow/validators/common/TemporalValidators/index.d.ts +2 -0
- package/dist/browser/Escrow/validators/common/TemporalValidators/index.d.ts.map +1 -0
- package/dist/browser/Escrow/validators/common/TemporalValidators/validateWithinWindow.d.cts +6 -0
- package/dist/browser/Escrow/validators/common/TemporalValidators/validateWithinWindow.d.cts.map +1 -0
- package/dist/browser/Escrow/validators/common/TemporalValidators/validateWithinWindow.d.mts +6 -0
- package/dist/browser/Escrow/validators/common/TemporalValidators/validateWithinWindow.d.mts.map +1 -0
- package/dist/browser/Escrow/validators/common/TemporalValidators/validateWithinWindow.d.ts +6 -0
- package/dist/browser/Escrow/validators/common/TemporalValidators/validateWithinWindow.d.ts.map +1 -0
- package/dist/browser/Escrow/validators/common/index.d.cts +3 -0
- package/dist/browser/Escrow/validators/common/index.d.cts.map +1 -0
- package/dist/browser/Escrow/validators/common/index.d.mts +3 -0
- package/dist/browser/Escrow/validators/common/index.d.mts.map +1 -0
- package/dist/browser/Escrow/validators/common/index.d.ts +3 -0
- package/dist/browser/Escrow/validators/common/index.d.ts.map +1 -0
- package/dist/browser/Escrow/validators/escrow/agent.d.cts +4 -0
- package/dist/browser/Escrow/validators/escrow/agent.d.cts.map +1 -0
- package/dist/browser/Escrow/validators/escrow/agent.d.mts +4 -0
- package/dist/browser/Escrow/validators/escrow/agent.d.mts.map +1 -0
- package/dist/browser/Escrow/validators/escrow/agent.d.ts +4 -0
- package/dist/browser/Escrow/validators/escrow/agent.d.ts.map +1 -0
- package/dist/browser/Escrow/validators/escrow/appraisal.d.cts +29 -0
- package/dist/browser/Escrow/validators/escrow/appraisal.d.cts.map +1 -0
- package/dist/browser/Escrow/validators/escrow/appraisal.d.mts +29 -0
- package/dist/browser/Escrow/validators/escrow/appraisal.d.mts.map +1 -0
- package/dist/browser/Escrow/validators/escrow/appraisal.d.ts +29 -0
- package/dist/browser/Escrow/validators/escrow/appraisal.d.ts.map +1 -0
- package/dist/browser/Escrow/validators/escrow/appraisalAuthorities.d.cts +9 -0
- package/dist/browser/Escrow/validators/escrow/appraisalAuthorities.d.cts.map +1 -0
- package/dist/browser/Escrow/validators/escrow/appraisalAuthorities.d.mts +9 -0
- package/dist/browser/Escrow/validators/escrow/appraisalAuthorities.d.mts.map +1 -0
- package/dist/browser/Escrow/validators/escrow/appraisalAuthorities.d.ts +9 -0
- package/dist/browser/Escrow/validators/escrow/appraisalAuthorities.d.ts.map +1 -0
- package/dist/browser/Escrow/validators/escrow/assets.d.cts +7 -0
- package/dist/browser/Escrow/validators/escrow/assets.d.cts.map +1 -0
- package/dist/browser/Escrow/validators/escrow/assets.d.mts +7 -0
- package/dist/browser/Escrow/validators/escrow/assets.d.mts.map +1 -0
- package/dist/browser/Escrow/validators/escrow/assets.d.ts +7 -0
- package/dist/browser/Escrow/validators/escrow/assets.d.ts.map +1 -0
- package/dist/browser/Escrow/validators/escrow/buyer.d.cts +7 -0
- package/dist/browser/Escrow/validators/escrow/buyer.d.cts.map +1 -0
- package/dist/browser/Escrow/validators/escrow/buyer.d.mts +7 -0
- package/dist/browser/Escrow/validators/escrow/buyer.d.mts.map +1 -0
- package/dist/browser/Escrow/validators/escrow/buyer.d.ts +7 -0
- package/dist/browser/Escrow/validators/escrow/buyer.d.ts.map +1 -0
- package/dist/browser/Escrow/validators/escrow/buyerSecret.d.cts +21 -0
- package/dist/browser/Escrow/validators/escrow/buyerSecret.d.cts.map +1 -0
- package/dist/browser/Escrow/validators/escrow/buyerSecret.d.mts +21 -0
- package/dist/browser/Escrow/validators/escrow/buyerSecret.d.mts.map +1 -0
- package/dist/browser/Escrow/validators/escrow/buyerSecret.d.ts +21 -0
- package/dist/browser/Escrow/validators/escrow/buyerSecret.d.ts.map +1 -0
- package/dist/browser/Escrow/validators/escrow/index.d.cts +11 -0
- package/dist/browser/Escrow/validators/escrow/index.d.cts.map +1 -0
- package/dist/browser/Escrow/validators/escrow/index.d.mts +11 -0
- package/dist/browser/Escrow/validators/escrow/index.d.mts.map +1 -0
- package/dist/browser/Escrow/validators/escrow/index.d.ts +11 -0
- package/dist/browser/Escrow/validators/escrow/index.d.ts.map +1 -0
- package/dist/browser/Escrow/validators/escrow/nbfExp.d.cts +3 -0
- package/dist/browser/Escrow/validators/escrow/nbfExp.d.cts.map +1 -0
- package/dist/browser/Escrow/validators/escrow/nbfExp.d.mts +3 -0
- package/dist/browser/Escrow/validators/escrow/nbfExp.d.mts.map +1 -0
- package/dist/browser/Escrow/validators/escrow/nbfExp.d.ts +3 -0
- package/dist/browser/Escrow/validators/escrow/nbfExp.d.ts.map +1 -0
- package/dist/browser/Escrow/validators/escrow/paymentAuthorities.d.cts +4 -0
- package/dist/browser/Escrow/validators/escrow/paymentAuthorities.d.cts.map +1 -0
- package/dist/browser/Escrow/validators/escrow/paymentAuthorities.d.mts +4 -0
- package/dist/browser/Escrow/validators/escrow/paymentAuthorities.d.mts.map +1 -0
- package/dist/browser/Escrow/validators/escrow/paymentAuthorities.d.ts +4 -0
- package/dist/browser/Escrow/validators/escrow/paymentAuthorities.d.ts.map +1 -0
- package/dist/browser/Escrow/validators/escrow/seller.d.cts +7 -0
- package/dist/browser/Escrow/validators/escrow/seller.d.cts.map +1 -0
- package/dist/browser/Escrow/validators/escrow/seller.d.mts +7 -0
- package/dist/browser/Escrow/validators/escrow/seller.d.mts.map +1 -0
- package/dist/browser/Escrow/validators/escrow/seller.d.ts +7 -0
- package/dist/browser/Escrow/validators/escrow/seller.d.ts.map +1 -0
- package/dist/browser/Escrow/validators/escrow/sellerSecret.d.cts +21 -0
- package/dist/browser/Escrow/validators/escrow/sellerSecret.d.cts.map +1 -0
- package/dist/browser/Escrow/validators/escrow/sellerSecret.d.mts +21 -0
- package/dist/browser/Escrow/validators/escrow/sellerSecret.d.mts.map +1 -0
- package/dist/browser/Escrow/validators/escrow/sellerSecret.d.ts +21 -0
- package/dist/browser/Escrow/validators/escrow/sellerSecret.d.ts.map +1 -0
- package/dist/browser/Escrow/validators/index.d.cts +4 -0
- package/dist/browser/Escrow/validators/index.d.cts.map +1 -0
- package/dist/browser/Escrow/validators/index.d.mts +4 -0
- package/dist/browser/Escrow/validators/index.d.mts.map +1 -0
- package/dist/browser/Escrow/validators/index.d.ts +4 -0
- package/dist/browser/Escrow/validators/index.d.ts.map +1 -0
- package/dist/browser/Escrow/validators/types/escrowValidation.d.cts +26 -0
- package/dist/browser/Escrow/validators/types/escrowValidation.d.cts.map +1 -0
- package/dist/browser/Escrow/validators/types/escrowValidation.d.mts +26 -0
- package/dist/browser/Escrow/validators/types/escrowValidation.d.mts.map +1 -0
- package/dist/browser/Escrow/validators/types/escrowValidation.d.ts +26 -0
- package/dist/browser/Escrow/validators/types/escrowValidation.d.ts.map +1 -0
- package/dist/browser/Escrow/validators/types/index.d.cts +2 -0
- package/dist/browser/Escrow/validators/types/index.d.cts.map +1 -0
- package/dist/browser/Escrow/validators/types/index.d.mts +2 -0
- package/dist/browser/Escrow/validators/types/index.d.mts.map +1 -0
- package/dist/browser/Escrow/validators/types/index.d.ts +2 -0
- package/dist/browser/Escrow/validators/types/index.d.ts.map +1 -0
- package/dist/browser/index.cjs +337 -3
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +335 -1
- package/dist/browser/index.js.map +1 -1
- package/dist/node/Escrow/index.d.cts +1 -0
- package/dist/node/Escrow/index.d.cts.map +1 -1
- package/dist/node/Escrow/index.d.mts +1 -0
- package/dist/node/Escrow/index.d.mts.map +1 -1
- package/dist/node/Escrow/index.d.ts +1 -0
- package/dist/node/Escrow/index.d.ts.map +1 -1
- package/dist/node/Escrow/validators/common/ModuleInstanceValidators/index.d.cts +2 -0
- package/dist/node/Escrow/validators/common/ModuleInstanceValidators/index.d.cts.map +1 -0
- package/dist/node/Escrow/validators/common/ModuleInstanceValidators/index.d.mts +2 -0
- package/dist/node/Escrow/validators/common/ModuleInstanceValidators/index.d.mts.map +1 -0
- package/dist/node/Escrow/validators/common/ModuleInstanceValidators/index.d.ts +2 -0
- package/dist/node/Escrow/validators/common/ModuleInstanceValidators/index.d.ts.map +1 -0
- package/dist/node/Escrow/validators/common/ModuleInstanceValidators/moduleInstanceValidators.d.cts +22 -0
- package/dist/node/Escrow/validators/common/ModuleInstanceValidators/moduleInstanceValidators.d.cts.map +1 -0
- package/dist/node/Escrow/validators/common/ModuleInstanceValidators/moduleInstanceValidators.d.mts +22 -0
- package/dist/node/Escrow/validators/common/ModuleInstanceValidators/moduleInstanceValidators.d.mts.map +1 -0
- package/dist/node/Escrow/validators/common/ModuleInstanceValidators/moduleInstanceValidators.d.ts +22 -0
- package/dist/node/Escrow/validators/common/ModuleInstanceValidators/moduleInstanceValidators.d.ts.map +1 -0
- package/dist/node/Escrow/validators/common/TemporalValidators/index.d.cts +2 -0
- package/dist/node/Escrow/validators/common/TemporalValidators/index.d.cts.map +1 -0
- package/dist/node/Escrow/validators/common/TemporalValidators/index.d.mts +2 -0
- package/dist/node/Escrow/validators/common/TemporalValidators/index.d.mts.map +1 -0
- package/dist/node/Escrow/validators/common/TemporalValidators/index.d.ts +2 -0
- package/dist/node/Escrow/validators/common/TemporalValidators/index.d.ts.map +1 -0
- package/dist/node/Escrow/validators/common/TemporalValidators/validateWithinWindow.d.cts +6 -0
- package/dist/node/Escrow/validators/common/TemporalValidators/validateWithinWindow.d.cts.map +1 -0
- package/dist/node/Escrow/validators/common/TemporalValidators/validateWithinWindow.d.mts +6 -0
- package/dist/node/Escrow/validators/common/TemporalValidators/validateWithinWindow.d.mts.map +1 -0
- package/dist/node/Escrow/validators/common/TemporalValidators/validateWithinWindow.d.ts +6 -0
- package/dist/node/Escrow/validators/common/TemporalValidators/validateWithinWindow.d.ts.map +1 -0
- package/dist/node/Escrow/validators/common/index.d.cts +3 -0
- package/dist/node/Escrow/validators/common/index.d.cts.map +1 -0
- package/dist/node/Escrow/validators/common/index.d.mts +3 -0
- package/dist/node/Escrow/validators/common/index.d.mts.map +1 -0
- package/dist/node/Escrow/validators/common/index.d.ts +3 -0
- package/dist/node/Escrow/validators/common/index.d.ts.map +1 -0
- package/dist/node/Escrow/validators/escrow/agent.d.cts +4 -0
- package/dist/node/Escrow/validators/escrow/agent.d.cts.map +1 -0
- package/dist/node/Escrow/validators/escrow/agent.d.mts +4 -0
- package/dist/node/Escrow/validators/escrow/agent.d.mts.map +1 -0
- package/dist/node/Escrow/validators/escrow/agent.d.ts +4 -0
- package/dist/node/Escrow/validators/escrow/agent.d.ts.map +1 -0
- package/dist/node/Escrow/validators/escrow/appraisal.d.cts +29 -0
- package/dist/node/Escrow/validators/escrow/appraisal.d.cts.map +1 -0
- package/dist/node/Escrow/validators/escrow/appraisal.d.mts +29 -0
- package/dist/node/Escrow/validators/escrow/appraisal.d.mts.map +1 -0
- package/dist/node/Escrow/validators/escrow/appraisal.d.ts +29 -0
- package/dist/node/Escrow/validators/escrow/appraisal.d.ts.map +1 -0
- package/dist/node/Escrow/validators/escrow/appraisalAuthorities.d.cts +9 -0
- package/dist/node/Escrow/validators/escrow/appraisalAuthorities.d.cts.map +1 -0
- package/dist/node/Escrow/validators/escrow/appraisalAuthorities.d.mts +9 -0
- package/dist/node/Escrow/validators/escrow/appraisalAuthorities.d.mts.map +1 -0
- package/dist/node/Escrow/validators/escrow/appraisalAuthorities.d.ts +9 -0
- package/dist/node/Escrow/validators/escrow/appraisalAuthorities.d.ts.map +1 -0
- package/dist/node/Escrow/validators/escrow/assets.d.cts +7 -0
- package/dist/node/Escrow/validators/escrow/assets.d.cts.map +1 -0
- package/dist/node/Escrow/validators/escrow/assets.d.mts +7 -0
- package/dist/node/Escrow/validators/escrow/assets.d.mts.map +1 -0
- package/dist/node/Escrow/validators/escrow/assets.d.ts +7 -0
- package/dist/node/Escrow/validators/escrow/assets.d.ts.map +1 -0
- package/dist/node/Escrow/validators/escrow/buyer.d.cts +7 -0
- package/dist/node/Escrow/validators/escrow/buyer.d.cts.map +1 -0
- package/dist/node/Escrow/validators/escrow/buyer.d.mts +7 -0
- package/dist/node/Escrow/validators/escrow/buyer.d.mts.map +1 -0
- package/dist/node/Escrow/validators/escrow/buyer.d.ts +7 -0
- package/dist/node/Escrow/validators/escrow/buyer.d.ts.map +1 -0
- package/dist/node/Escrow/validators/escrow/buyerSecret.d.cts +21 -0
- package/dist/node/Escrow/validators/escrow/buyerSecret.d.cts.map +1 -0
- package/dist/node/Escrow/validators/escrow/buyerSecret.d.mts +21 -0
- package/dist/node/Escrow/validators/escrow/buyerSecret.d.mts.map +1 -0
- package/dist/node/Escrow/validators/escrow/buyerSecret.d.ts +21 -0
- package/dist/node/Escrow/validators/escrow/buyerSecret.d.ts.map +1 -0
- package/dist/node/Escrow/validators/escrow/index.d.cts +11 -0
- package/dist/node/Escrow/validators/escrow/index.d.cts.map +1 -0
- package/dist/node/Escrow/validators/escrow/index.d.mts +11 -0
- package/dist/node/Escrow/validators/escrow/index.d.mts.map +1 -0
- package/dist/node/Escrow/validators/escrow/index.d.ts +11 -0
- package/dist/node/Escrow/validators/escrow/index.d.ts.map +1 -0
- package/dist/node/Escrow/validators/escrow/nbfExp.d.cts +3 -0
- package/dist/node/Escrow/validators/escrow/nbfExp.d.cts.map +1 -0
- package/dist/node/Escrow/validators/escrow/nbfExp.d.mts +3 -0
- package/dist/node/Escrow/validators/escrow/nbfExp.d.mts.map +1 -0
- package/dist/node/Escrow/validators/escrow/nbfExp.d.ts +3 -0
- package/dist/node/Escrow/validators/escrow/nbfExp.d.ts.map +1 -0
- package/dist/node/Escrow/validators/escrow/paymentAuthorities.d.cts +4 -0
- package/dist/node/Escrow/validators/escrow/paymentAuthorities.d.cts.map +1 -0
- package/dist/node/Escrow/validators/escrow/paymentAuthorities.d.mts +4 -0
- package/dist/node/Escrow/validators/escrow/paymentAuthorities.d.mts.map +1 -0
- package/dist/node/Escrow/validators/escrow/paymentAuthorities.d.ts +4 -0
- package/dist/node/Escrow/validators/escrow/paymentAuthorities.d.ts.map +1 -0
- package/dist/node/Escrow/validators/escrow/seller.d.cts +7 -0
- package/dist/node/Escrow/validators/escrow/seller.d.cts.map +1 -0
- package/dist/node/Escrow/validators/escrow/seller.d.mts +7 -0
- package/dist/node/Escrow/validators/escrow/seller.d.mts.map +1 -0
- package/dist/node/Escrow/validators/escrow/seller.d.ts +7 -0
- package/dist/node/Escrow/validators/escrow/seller.d.ts.map +1 -0
- package/dist/node/Escrow/validators/escrow/sellerSecret.d.cts +21 -0
- package/dist/node/Escrow/validators/escrow/sellerSecret.d.cts.map +1 -0
- package/dist/node/Escrow/validators/escrow/sellerSecret.d.mts +21 -0
- package/dist/node/Escrow/validators/escrow/sellerSecret.d.mts.map +1 -0
- package/dist/node/Escrow/validators/escrow/sellerSecret.d.ts +21 -0
- package/dist/node/Escrow/validators/escrow/sellerSecret.d.ts.map +1 -0
- package/dist/node/Escrow/validators/index.d.cts +4 -0
- package/dist/node/Escrow/validators/index.d.cts.map +1 -0
- package/dist/node/Escrow/validators/index.d.mts +4 -0
- package/dist/node/Escrow/validators/index.d.mts.map +1 -0
- package/dist/node/Escrow/validators/index.d.ts +4 -0
- package/dist/node/Escrow/validators/index.d.ts.map +1 -0
- package/dist/node/Escrow/validators/types/escrowValidation.d.cts +26 -0
- package/dist/node/Escrow/validators/types/escrowValidation.d.cts.map +1 -0
- package/dist/node/Escrow/validators/types/escrowValidation.d.mts +26 -0
- package/dist/node/Escrow/validators/types/escrowValidation.d.mts.map +1 -0
- package/dist/node/Escrow/validators/types/escrowValidation.d.ts +26 -0
- package/dist/node/Escrow/validators/types/escrowValidation.d.ts.map +1 -0
- package/dist/node/Escrow/validators/types/index.d.cts +2 -0
- package/dist/node/Escrow/validators/types/index.d.cts.map +1 -0
- package/dist/node/Escrow/validators/types/index.d.mts +2 -0
- package/dist/node/Escrow/validators/types/index.d.mts.map +1 -0
- package/dist/node/Escrow/validators/types/index.d.ts +2 -0
- package/dist/node/Escrow/validators/types/index.d.ts.map +1 -0
- package/dist/node/index.cjs +359 -4
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +335 -1
- package/dist/node/index.js.map +1 -1
- package/package.json +10 -5
- package/src/Escrow/index.ts +1 -0
- package/src/Escrow/validators/common/ModuleInstanceValidators/index.ts +1 -0
- package/src/Escrow/validators/common/ModuleInstanceValidators/moduleInstanceValidators.ts +48 -0
- package/src/Escrow/validators/common/TemporalValidators/index.ts +1 -0
- package/src/Escrow/validators/common/TemporalValidators/validateWithinWindow.ts +7 -0
- package/src/Escrow/validators/common/index.ts +2 -0
- package/src/Escrow/validators/escrow/agent.ts +17 -0
- package/src/Escrow/validators/escrow/appraisal.ts +129 -0
- package/src/Escrow/validators/escrow/appraisalAuthorities.ts +37 -0
- package/src/Escrow/validators/escrow/assets.ts +18 -0
- package/src/Escrow/validators/escrow/buyer.ts +25 -0
- package/src/Escrow/validators/escrow/buyerSecret.ts +75 -0
- package/src/Escrow/validators/escrow/index.ts +10 -0
- package/src/Escrow/validators/escrow/nbfExp.ts +18 -0
- package/src/Escrow/validators/escrow/paymentAuthorities.ts +17 -0
- package/src/Escrow/validators/escrow/seller.ts +25 -0
- package/src/Escrow/validators/escrow/sellerSecret.ts +75 -0
- package/src/Escrow/validators/index.ts +3 -0
- package/src/Escrow/validators/types/escrowValidation.ts +30 -0
- package/src/Escrow/validators/types/index.ts +1 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type Windowed = { exp?: number; nbf?: number }
|
|
2
|
+
|
|
3
|
+
export const validateWithinWindow = (value: Windowed, exp: number, nbf: number = Date.now()): boolean => {
|
|
4
|
+
if (value.nbf === undefined || value.nbf > nbf) return false
|
|
5
|
+
if (value.exp === undefined || value.exp < exp) return false
|
|
6
|
+
return true
|
|
7
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ModuleIdentifier } from '@xyo-network/module-model'
|
|
2
|
+
|
|
3
|
+
import { EscrowTerms } from '../../Terms'
|
|
4
|
+
import { moduleIdentifiersContainsOneOf } from '../common'
|
|
5
|
+
import { EscrowTermsValidationFunction } from '../types'
|
|
6
|
+
|
|
7
|
+
const name = 'EscrowTerms.escrowAgent'
|
|
8
|
+
|
|
9
|
+
export const getEscrowAgentAllowedValidator = (allowedEscrowAgent: ModuleIdentifier): EscrowTermsValidationFunction => {
|
|
10
|
+
return (terms: EscrowTerms) => {
|
|
11
|
+
const result = moduleIdentifiersContainsOneOf(terms, (t) => t.escrowAgent, [allowedEscrowAgent], true)
|
|
12
|
+
if (!result) {
|
|
13
|
+
console.log(`${name}: Escrow agent not allowed: ${terms.escrowAgent}`)
|
|
14
|
+
}
|
|
15
|
+
return result
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { assertEx } from '@xylabs/assert'
|
|
2
|
+
import { Hash } from '@xylabs/hex'
|
|
3
|
+
import { BoundWitness, isBoundWitnessWithMeta } from '@xyo-network/boundwitness-model'
|
|
4
|
+
import { HashLeaseEstimate, isHashLeaseEstimateWithSources } from '@xyo-network/diviner-hash-lease'
|
|
5
|
+
import { Payload, WithMeta, WithSources } from '@xyo-network/payload-model'
|
|
6
|
+
|
|
7
|
+
import { EscrowTerms } from '../../Terms'
|
|
8
|
+
import { validateWithinWindow } from '../common'
|
|
9
|
+
import { EscrowTermsValidationFunction } from '../types'
|
|
10
|
+
|
|
11
|
+
const name = 'EscrowTerms.appraisal'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A function that validates the escrow terms for tbe existence of appraisals
|
|
15
|
+
* @returns True if the escrow terms contain appraisals, false otherwise
|
|
16
|
+
*/
|
|
17
|
+
export const appraisalsExistValidator: EscrowTermsValidationFunction = (terms: EscrowTerms) => {
|
|
18
|
+
// Validate we have appraisals
|
|
19
|
+
const appraisals = terms.appraisals
|
|
20
|
+
if (!appraisals || appraisals.length === 0) {
|
|
21
|
+
console.log(`${name}: No appraisals: ${terms.appraisals}`)
|
|
22
|
+
return false
|
|
23
|
+
}
|
|
24
|
+
return true
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Returns a function that validates the escrow terms for appraisals which are from valid authorities
|
|
29
|
+
* @param dictionary Payload dictionary of the escrow terms
|
|
30
|
+
* @returns A function that validates the escrow terms for appraisals which are from valid authorities
|
|
31
|
+
*/
|
|
32
|
+
export const getAppraisalsFromValidAuthoritiesValidator = (dictionary: Record<Hash, WithMeta<Payload>>): EscrowTermsValidationFunction => {
|
|
33
|
+
return (terms: EscrowTerms) => {
|
|
34
|
+
const appraisals = assertEx(terms.appraisals, () => `${name}: No appraisals: ${terms.appraisals}`)
|
|
35
|
+
const appraisalAuthorities = assertEx(terms.appraisalAuthorities, () => `${name}: No appraisalAuthorities: ${terms.appraisalAuthorities}`)
|
|
36
|
+
|
|
37
|
+
// Validate the appraisals are signed by valid appraisal authorities. Validation criteria:
|
|
38
|
+
// - We have a bw for each of the appraisal
|
|
39
|
+
// - The bw is signed by an approved appraisal authority
|
|
40
|
+
const appraisalBWsValid: Record<Hash, WithMeta<BoundWitness>[]> = Object.fromEntries(
|
|
41
|
+
appraisals.map<[Hash, WithMeta<BoundWitness>[]]>((hash) => [hash, []]),
|
|
42
|
+
)
|
|
43
|
+
for (const bw of Object.values(dictionary).filter(isBoundWitnessWithMeta)) {
|
|
44
|
+
for (const appraisal of appraisals) {
|
|
45
|
+
if (bw.payload_hashes.includes(appraisal) && bw.addresses.some((address) => appraisalAuthorities.includes(address))) {
|
|
46
|
+
appraisalBWsValid[appraisal].push(bw)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
for (const [appraisal, bws] of Object.entries(appraisalBWsValid)) {
|
|
51
|
+
if (bws.length === 0) {
|
|
52
|
+
console.log(`${name}: No valid appraisals for ${appraisal}`)
|
|
53
|
+
return false
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return true
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Returns a function that validates the escrow terms for appraisals which are valid
|
|
62
|
+
* @param dictionary Payload dictionary of the escrow terms
|
|
63
|
+
* @param minimumExp The minium amount of time an estimate needs to be valid
|
|
64
|
+
* for in the future (so as not to expire before the escrow is complete)
|
|
65
|
+
* @returns A function that validates the escrow terms for appraisals which are valid
|
|
66
|
+
*/
|
|
67
|
+
export const getAppraisalsValidValidator = (dictionary: Record<Hash, WithMeta<Payload>>, minimumExp: number): EscrowTermsValidationFunction => {
|
|
68
|
+
return (terms: EscrowTerms) => {
|
|
69
|
+
// Verify we have an estimate for each of the assets
|
|
70
|
+
const estimatesByAsset = getEstimatesByAsset(terms, dictionary)
|
|
71
|
+
// Validate each of the estimates are valid (time, price, etc)
|
|
72
|
+
const now = Date.now()
|
|
73
|
+
const exp = now + minimumExp
|
|
74
|
+
for (const [asset, estimates] of Object.entries(estimatesByAsset)) {
|
|
75
|
+
for (const estimate of estimates) {
|
|
76
|
+
if (!validateEstimate(estimate, exp)) {
|
|
77
|
+
console.log(`${name}: Invalid estimate for asset ${asset}: ${estimate}`)
|
|
78
|
+
return false
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return true
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Returns a function that validates the escrow terms to ensure that they contain an appraisal for each asset
|
|
88
|
+
* @param dictionary Payload dictionary of the escrow terms
|
|
89
|
+
* @returns A function that validates the escrow terms for appraisals
|
|
90
|
+
*/
|
|
91
|
+
export const getAppraisalsForAllAssetsValidator = (dictionary: Record<Hash, WithMeta<Payload>>): EscrowTermsValidationFunction => {
|
|
92
|
+
return (terms: EscrowTerms) => {
|
|
93
|
+
// Verify we have an estimate for each of the assets
|
|
94
|
+
const estimatesByAsset = getEstimatesByAsset(terms, dictionary)
|
|
95
|
+
const assets = assertEx(terms.assets, () => `${name}: No assets: ${terms.assets}`)
|
|
96
|
+
if (Object.keys(estimatesByAsset).length !== assets.length) {
|
|
97
|
+
console.log(`${name}: Missing appraisals for all assets: ${assets}`)
|
|
98
|
+
return false
|
|
99
|
+
}
|
|
100
|
+
return true
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const validateEstimate = (estimate: WithSources<HashLeaseEstimate>, exp: number): boolean => {
|
|
105
|
+
if (!validateWithinWindow(estimate, exp)) return false
|
|
106
|
+
if (estimate.currency !== 'USD') return false
|
|
107
|
+
if (estimate.price <= 0) return false
|
|
108
|
+
return true
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const getEstimatesByAsset = (terms: EscrowTerms, dictionary: Record<Hash, WithMeta<Payload>>): Record<Hash, WithSources<HashLeaseEstimate>[]> => {
|
|
112
|
+
const assets = assertEx(terms.assets, () => `${name}: No assets: ${terms.assets}`)
|
|
113
|
+
const estimates = Object.values(dictionary).filter(isHashLeaseEstimateWithSources) as unknown as WithSources<HashLeaseEstimate>[]
|
|
114
|
+
const estimatesByAsset: Record<Hash, WithSources<HashLeaseEstimate>[]> = {}
|
|
115
|
+
for (const estimate of estimates) {
|
|
116
|
+
const { sources } = estimate
|
|
117
|
+
if (sources === undefined || sources.length === 0) {
|
|
118
|
+
console.log(`${name}: No sources: ${estimate}`)
|
|
119
|
+
continue
|
|
120
|
+
}
|
|
121
|
+
for (const asset of assets) {
|
|
122
|
+
if (sources.includes(asset)) {
|
|
123
|
+
if (!estimatesByAsset[asset]) estimatesByAsset[asset] = []
|
|
124
|
+
estimatesByAsset[asset].push(estimate)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return estimatesByAsset
|
|
129
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { asAddress } from '@xylabs/hex'
|
|
2
|
+
import { ModuleIdentifier } from '@xyo-network/module-model'
|
|
3
|
+
|
|
4
|
+
import { EscrowTerms } from '../../Terms'
|
|
5
|
+
import { moduleIdentifiersContainsAllOf } from '../common'
|
|
6
|
+
import { EscrowTermsValidationFunction } from '../types'
|
|
7
|
+
|
|
8
|
+
const name = 'EscrowTerms.appraisalAuthorities'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A function that validates the escrow terms for appraisalAuthorities
|
|
12
|
+
* @returns True if the escrow terms contain appraisalAuthorities, false otherwise
|
|
13
|
+
*/
|
|
14
|
+
export const appraisalAuthoritiesExistValidator: EscrowTermsValidationFunction = (terms: EscrowTerms) => {
|
|
15
|
+
// Validate we have appraisalAuthorities
|
|
16
|
+
const appraisalAuthorities = terms.appraisalAuthorities
|
|
17
|
+
if (!appraisalAuthorities || appraisalAuthorities.length === 0) {
|
|
18
|
+
console.log(`${name}: No appraisalAuthorities: ${terms.appraisalAuthorities}`)
|
|
19
|
+
return false
|
|
20
|
+
}
|
|
21
|
+
// Validate the authorities are addresses
|
|
22
|
+
if (appraisalAuthorities.map((x) => asAddress(x)).length !== appraisalAuthorities.length) {
|
|
23
|
+
console.log(`${name}: Invalid address: ${terms.appraisalAuthorities}`)
|
|
24
|
+
return false
|
|
25
|
+
}
|
|
26
|
+
return true
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const getAppraisalAuthoritiesAllowedValidator = (allowed: ModuleIdentifier[]): EscrowTermsValidationFunction => {
|
|
30
|
+
return (terms: EscrowTerms) => {
|
|
31
|
+
const result = moduleIdentifiersContainsAllOf(terms, (t) => t.appraisalAuthorities, allowed, true)
|
|
32
|
+
if (!result) {
|
|
33
|
+
console.log(`${name}: Appraisal authority not allowed: ${terms.appraisalAuthorities}`)
|
|
34
|
+
}
|
|
35
|
+
return result
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { EscrowTerms } from '../../Terms'
|
|
2
|
+
import { EscrowTermsValidationFunction } from '../types'
|
|
3
|
+
|
|
4
|
+
const name = 'EscrowTerms.assets'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Returns a function that validates the escrow terms for assets
|
|
8
|
+
* @returns A function that validates the escrow terms for assets
|
|
9
|
+
*/
|
|
10
|
+
export const assetsExistValidator: EscrowTermsValidationFunction = (terms: EscrowTerms) => {
|
|
11
|
+
// Validate we have assets
|
|
12
|
+
const assets = terms.assets
|
|
13
|
+
if (!assets || assets.length === 0) {
|
|
14
|
+
console.log(`${name}: No assets: ${terms.assets}`)
|
|
15
|
+
return false
|
|
16
|
+
}
|
|
17
|
+
return true
|
|
18
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { asAddress } from '@xylabs/hex'
|
|
2
|
+
|
|
3
|
+
import { EscrowTerms } from '../../Terms'
|
|
4
|
+
import { EscrowTermsValidationFunction } from '../types'
|
|
5
|
+
|
|
6
|
+
const name = 'EscrowTerms.buyer'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A function that validates the escrow terms for buyer
|
|
10
|
+
* @returns True if the escrow terms contain buyer, false otherwise
|
|
11
|
+
*/
|
|
12
|
+
export const buyerExistsValidator: EscrowTermsValidationFunction = (terms: EscrowTerms) => {
|
|
13
|
+
// Validate we have buyer
|
|
14
|
+
const buyer = terms.buyer
|
|
15
|
+
if (!buyer || buyer.length === 0) {
|
|
16
|
+
console.log(`${name}: No buyer: ${terms.buyer}`)
|
|
17
|
+
return false
|
|
18
|
+
}
|
|
19
|
+
// Validate the authorities are addresses
|
|
20
|
+
if (buyer.map((x) => asAddress(x)).length !== buyer.length) {
|
|
21
|
+
console.log(`${name}: Invalid address: ${terms.buyer}`)
|
|
22
|
+
return false
|
|
23
|
+
}
|
|
24
|
+
return true
|
|
25
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { assertEx } from '@xylabs/assert'
|
|
2
|
+
import { Hash } from '@xylabs/hex'
|
|
3
|
+
import { isBoundWitnessWithMeta } from '@xyo-network/boundwitness-model'
|
|
4
|
+
import { BoundWitnessValidator } from '@xyo-network/boundwitness-validator'
|
|
5
|
+
import { Payload, WithMeta } from '@xyo-network/payload-model'
|
|
6
|
+
|
|
7
|
+
import { EscrowTerms } from '../../Terms'
|
|
8
|
+
import { EscrowTermsValidationFunction } from '../types'
|
|
9
|
+
|
|
10
|
+
const name = 'EscrowTerms.buyerSecret'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Returns a function that validates the escrow terms for buyerSecret
|
|
14
|
+
* @returns A function that validates the escrow terms for buyerSecret
|
|
15
|
+
*/
|
|
16
|
+
export const buyerSecretExistsValidator: EscrowTermsValidationFunction = (terms: EscrowTerms) => {
|
|
17
|
+
// Validate we have buyerSecret
|
|
18
|
+
const buyerSecret = terms.buyerSecret
|
|
19
|
+
if (!buyerSecret || buyerSecret.length === 0) {
|
|
20
|
+
console.log(`${name}: No buyerSecret: ${terms.buyerSecret}`)
|
|
21
|
+
return false
|
|
22
|
+
}
|
|
23
|
+
return true
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Returns a function that validates the escrow terms for the existence of the buyerSecret in the dictionary
|
|
28
|
+
* @param dictionary Payload dictionary of the escrow terms
|
|
29
|
+
* @returns A function that validates the escrow terms for the existence of the buyerSecret in the dictionary
|
|
30
|
+
*/
|
|
31
|
+
export const getBuyerSecretSuppliedValidator = (dictionary: Record<Hash, WithMeta<Payload>>): EscrowTermsValidationFunction => {
|
|
32
|
+
return (terms: EscrowTerms) => {
|
|
33
|
+
const buyerSecret = assertEx(terms.buyerSecret, () => `${name}: No buyerSecret: ${terms.buyerSecret}`)
|
|
34
|
+
if (!dictionary[buyerSecret]) {
|
|
35
|
+
console.log(`${name}: Payload not supplied for buyerSecret: ${buyerSecret}`)
|
|
36
|
+
return false
|
|
37
|
+
}
|
|
38
|
+
return true
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Returns a function that validates the escrow terms for the existence of the buyerSecret signed by the buyer
|
|
44
|
+
* @param dictionary Payload dictionary of the escrow terms
|
|
45
|
+
* @returns A function that validates the escrow terms for the existence of the buyerSecret signed by the buyer
|
|
46
|
+
*/
|
|
47
|
+
export const getBuyerSecretSignedValidator = (dictionary: Record<Hash, WithMeta<Payload>>): EscrowTermsValidationFunction => {
|
|
48
|
+
return async (terms: EscrowTerms) => {
|
|
49
|
+
const buyer = assertEx(terms.buyer, () => `${name}: No buyer: ${terms.buyer}`)
|
|
50
|
+
const buyerSecret = assertEx(terms.buyerSecret, () => `${name}: No buyerSecret: ${terms.buyerSecret}`)
|
|
51
|
+
// Buyer-signed buyer secrets
|
|
52
|
+
const buyerSecretBWs = Object.values(dictionary)
|
|
53
|
+
// Find all BoundWitnesses
|
|
54
|
+
.filter(isBoundWitnessWithMeta)
|
|
55
|
+
// That contain the buyer secret
|
|
56
|
+
.filter((bw) => bw.payload_hashes.includes(buyerSecret))
|
|
57
|
+
// That are signed by all the buyers
|
|
58
|
+
.filter((bw) => buyer.every((buyerAddress) => bw.addresses.includes(buyerAddress)))
|
|
59
|
+
|
|
60
|
+
// If there are no buyerSecret BWs, return false
|
|
61
|
+
if (buyerSecretBWs.length === 0) {
|
|
62
|
+
console.log(`${name}: No BoundWitnesses supplied for buyerSecret: ${buyerSecret}`)
|
|
63
|
+
return false
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Ensure each BW supplied for the buyerSecret is valid
|
|
67
|
+
const errors = await Promise.all(buyerSecretBWs.map((bw) => new BoundWitnessValidator(bw).validate()))
|
|
68
|
+
const validBoundWitnesses = errors.every((errors) => errors.length === 0)
|
|
69
|
+
if (!validBoundWitnesses) {
|
|
70
|
+
console.log(`${name}: Invalid BoundWitnesses supplied for buyerSecret: ${buyerSecret}`)
|
|
71
|
+
return false
|
|
72
|
+
}
|
|
73
|
+
return true
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './agent'
|
|
2
|
+
export * from './appraisal'
|
|
3
|
+
export * from './appraisalAuthorities'
|
|
4
|
+
export * from './assets'
|
|
5
|
+
export * from './buyer'
|
|
6
|
+
export * from './buyerSecret'
|
|
7
|
+
export * from './nbfExp'
|
|
8
|
+
export * from './paymentAuthorities'
|
|
9
|
+
export * from './seller'
|
|
10
|
+
export * from './sellerSecret'
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { EscrowTerms } from '../../Terms'
|
|
2
|
+
import { EscrowTermsValidationFunction } from '../types'
|
|
3
|
+
|
|
4
|
+
export const getNbfExpValidator = (now: number, minRequiredDuration: number): EscrowTermsValidationFunction => {
|
|
5
|
+
const minExp = now + minRequiredDuration
|
|
6
|
+
return (terms: EscrowTerms) => {
|
|
7
|
+
const { exp, nbf } = terms
|
|
8
|
+
if (nbf === undefined || nbf < now) {
|
|
9
|
+
console.log(`EscrowTerms.nbf: invalid nbf ${terms.nbf}`)
|
|
10
|
+
return false
|
|
11
|
+
}
|
|
12
|
+
if (exp === undefined || exp < minExp || nbf > exp) {
|
|
13
|
+
console.log(`EscrowTerms.exp: invalid exp ${terms.exp}`)
|
|
14
|
+
return false
|
|
15
|
+
}
|
|
16
|
+
return true
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ModuleIdentifier } from '@xyo-network/module-model'
|
|
2
|
+
|
|
3
|
+
import { EscrowTerms } from '../../Terms'
|
|
4
|
+
import { moduleIdentifiersContainsAllOf } from '../common'
|
|
5
|
+
import { EscrowTermsValidationFunction } from '../types'
|
|
6
|
+
|
|
7
|
+
const name = 'EscrowTerms.paymentAuthorities'
|
|
8
|
+
|
|
9
|
+
export const getPaymentAuthoritiesAllowedValidator = (allowed: ModuleIdentifier[]): EscrowTermsValidationFunction => {
|
|
10
|
+
return (terms: EscrowTerms) => {
|
|
11
|
+
const result = moduleIdentifiersContainsAllOf(terms, (t) => t.paymentAuthorities, allowed, true)
|
|
12
|
+
if (!result) {
|
|
13
|
+
console.log(`${name}: Payment authority not allowed: ${terms.paymentAuthorities}`)
|
|
14
|
+
}
|
|
15
|
+
return result
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { asAddress } from '@xylabs/hex'
|
|
2
|
+
|
|
3
|
+
import { EscrowTerms } from '../../Terms'
|
|
4
|
+
import { EscrowTermsValidationFunction } from '../types'
|
|
5
|
+
|
|
6
|
+
const name = 'EscrowTerms.seller'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A function that validates the escrow terms for seller
|
|
10
|
+
* @returns True if the escrow terms contain seller, false otherwise
|
|
11
|
+
*/
|
|
12
|
+
export const sellerExistsValidator: EscrowTermsValidationFunction = (terms: EscrowTerms) => {
|
|
13
|
+
// Validate we have seller
|
|
14
|
+
const seller = terms.seller
|
|
15
|
+
if (!seller || seller.length === 0) {
|
|
16
|
+
console.log(`${name}: No seller: ${terms.seller}`)
|
|
17
|
+
return false
|
|
18
|
+
}
|
|
19
|
+
// Validate the authorities are addresses
|
|
20
|
+
if (seller.map((x) => asAddress(x)).length !== seller.length) {
|
|
21
|
+
console.log(`${name}: Invalid address: ${terms.seller}`)
|
|
22
|
+
return false
|
|
23
|
+
}
|
|
24
|
+
return true
|
|
25
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { assertEx } from '@xylabs/assert'
|
|
2
|
+
import { Hash } from '@xylabs/hex'
|
|
3
|
+
import { isBoundWitnessWithMeta } from '@xyo-network/boundwitness-model'
|
|
4
|
+
import { BoundWitnessValidator } from '@xyo-network/boundwitness-validator'
|
|
5
|
+
import { Payload, WithMeta } from '@xyo-network/payload-model'
|
|
6
|
+
|
|
7
|
+
import { EscrowTerms } from '../../Terms'
|
|
8
|
+
import { EscrowTermsValidationFunction } from '../types'
|
|
9
|
+
|
|
10
|
+
const name = 'EscrowTerms.sellerSecret'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Returns a function that validates the escrow terms for sellerSecret
|
|
14
|
+
* @returns A function that validates the escrow terms for sellerSecret
|
|
15
|
+
*/
|
|
16
|
+
export const sellerSecretExistsValidator: EscrowTermsValidationFunction = (terms: EscrowTerms) => {
|
|
17
|
+
// Validate we have sellerSecret
|
|
18
|
+
const sellerSecret = terms.sellerSecret
|
|
19
|
+
if (!sellerSecret || sellerSecret.length === 0) {
|
|
20
|
+
console.log(`${name}: No sellerSecret: ${terms.sellerSecret}`)
|
|
21
|
+
return false
|
|
22
|
+
}
|
|
23
|
+
return true
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Returns a function that validates the escrow terms for the existence of the sellerSecret in the dictionary
|
|
28
|
+
* @param dictionary Payload dictionary of the escrow terms
|
|
29
|
+
* @returns A function that validates the escrow terms for the existence of the sellerSecret in the dictionary
|
|
30
|
+
*/
|
|
31
|
+
export const getSellerSecretSuppliedValidator = (dictionary: Record<Hash, WithMeta<Payload>>): EscrowTermsValidationFunction => {
|
|
32
|
+
return (terms: EscrowTerms) => {
|
|
33
|
+
const sellerSecret = assertEx(terms.sellerSecret, () => `${name}: No sellerSecret: ${terms.sellerSecret}`)
|
|
34
|
+
if (!dictionary[sellerSecret]) {
|
|
35
|
+
console.log(`${name}: Payload not supplied for sellerSecret: ${sellerSecret}`)
|
|
36
|
+
return false
|
|
37
|
+
}
|
|
38
|
+
return true
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Returns a function that validates the escrow terms for the existence of the sellerSecret signed by the seller
|
|
44
|
+
* @param dictionary Payload dictionary of the escrow terms
|
|
45
|
+
* @returns A function that validates the escrow terms for the existence of the sellerSecret signed by the seller
|
|
46
|
+
*/
|
|
47
|
+
export const getSellerSecretSignedValidator = (dictionary: Record<Hash, WithMeta<Payload>>): EscrowTermsValidationFunction => {
|
|
48
|
+
return async (terms: EscrowTerms) => {
|
|
49
|
+
const seller = assertEx(terms.seller, () => `${name}: No seller: ${terms.seller}`)
|
|
50
|
+
const sellerSecret = assertEx(terms.sellerSecret, () => `${name}: No sellerSecret: ${terms.sellerSecret}`)
|
|
51
|
+
// Seller-signed seller secrets
|
|
52
|
+
const sellerSecretBWs = Object.values(dictionary)
|
|
53
|
+
// Find all BoundWitnesses
|
|
54
|
+
.filter(isBoundWitnessWithMeta)
|
|
55
|
+
// That contain the seller secret
|
|
56
|
+
.filter((bw) => bw.payload_hashes.includes(sellerSecret))
|
|
57
|
+
// That are signed by all the sellers
|
|
58
|
+
.filter((bw) => seller.every((sellerAddress) => bw.addresses.includes(sellerAddress)))
|
|
59
|
+
|
|
60
|
+
// If there are no sellerSecret BWs, return false
|
|
61
|
+
if (sellerSecretBWs.length === 0) {
|
|
62
|
+
console.log(`${name}: No BoundWitnesses supplied for sellerSecret: ${sellerSecret}`)
|
|
63
|
+
return false
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Ensure each BW supplied for the sellerSecret is valid
|
|
67
|
+
const errors = await Promise.all(sellerSecretBWs.map((bw) => new BoundWitnessValidator(bw).validate()))
|
|
68
|
+
const validBoundWitnesses = errors.every((errors) => errors.length === 0)
|
|
69
|
+
if (!validBoundWitnesses) {
|
|
70
|
+
console.log(`${name}: Invalid BoundWitnesses supplied for sellerSecret: ${sellerSecret}`)
|
|
71
|
+
return false
|
|
72
|
+
}
|
|
73
|
+
return true
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { EscrowTerms } from '../../Terms'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Type corresponding to the escrow terms properties
|
|
5
|
+
*/
|
|
6
|
+
export type EscrowTermsProperty = keyof EscrowTerms
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Type corresponding to the escrow terms property value
|
|
10
|
+
*/
|
|
11
|
+
export type EscrowTermsValue<K extends EscrowTermsProperty> = EscrowTerms[K]
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* An expressions that selects a property value from the escrow terms
|
|
15
|
+
*/
|
|
16
|
+
export type EscrowTermsValueExpression<
|
|
17
|
+
/**
|
|
18
|
+
* The property of the escrow terms to select
|
|
19
|
+
*/
|
|
20
|
+
K extends EscrowTermsProperty,
|
|
21
|
+
/**
|
|
22
|
+
* The type of the selected property's value
|
|
23
|
+
*/
|
|
24
|
+
V = EscrowTermsValue<K>,
|
|
25
|
+
> = (escrowTerms: EscrowTerms) => V
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A function that validates the supplied escrow terms
|
|
29
|
+
*/
|
|
30
|
+
export type EscrowTermsValidationFunction = (escrowTerms: EscrowTerms) => boolean | Promise<boolean>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './escrowValidation'
|