@xyo-network/payment-payload-plugins 5.3.2 → 5.3.3
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/neutral/Amount/Iso4217Currency.d.ts +14 -0
- package/dist/neutral/Amount/Iso4217Currency.d.ts.map +1 -0
- package/dist/neutral/Amount/Payload.d.ts +27 -0
- package/dist/neutral/Amount/Payload.d.ts.map +1 -0
- package/dist/neutral/Amount/index.d.ts +3 -0
- package/dist/neutral/Amount/index.d.ts.map +1 -0
- package/dist/neutral/Billing/Address/Address.d.ts +42 -0
- package/dist/neutral/Billing/Address/Address.d.ts.map +1 -0
- package/dist/neutral/Billing/Address/Schema.d.ts +5 -0
- package/dist/neutral/Billing/Address/Schema.d.ts.map +1 -0
- package/dist/neutral/Billing/Address/index.d.ts +3 -0
- package/dist/neutral/Billing/Address/index.d.ts.map +1 -0
- package/dist/neutral/Billing/Schema.d.ts +5 -0
- package/dist/neutral/Billing/Schema.d.ts.map +1 -0
- package/dist/neutral/Billing/index.d.ts +3 -0
- package/dist/neutral/Billing/index.d.ts.map +1 -0
- package/dist/neutral/Currency.d.ts +2 -0
- package/dist/neutral/Currency.d.ts.map +1 -0
- package/dist/neutral/Discount/Config.d.ts +25 -0
- package/dist/neutral/Discount/Config.d.ts.map +1 -0
- package/dist/neutral/Discount/Params.d.ts +11 -0
- package/dist/neutral/Discount/Params.d.ts.map +1 -0
- package/dist/neutral/Discount/Payload/Coupon/Conditions/AppraisalAmountCondition.d.ts +8 -0
- package/dist/neutral/Discount/Payload/Coupon/Conditions/AppraisalAmountCondition.d.ts.map +1 -0
- package/dist/neutral/Discount/Payload/Coupon/Conditions/AssetQuantityCondition.d.ts +8 -0
- package/dist/neutral/Discount/Payload/Coupon/Conditions/AssetQuantityCondition.d.ts.map +1 -0
- package/dist/neutral/Discount/Payload/Coupon/Conditions/BuyerCondition.d.ts +34 -0
- package/dist/neutral/Discount/Payload/Coupon/Conditions/BuyerCondition.d.ts.map +1 -0
- package/dist/neutral/Discount/Payload/Coupon/Conditions/index.d.ts +4 -0
- package/dist/neutral/Discount/Payload/Coupon/Conditions/index.d.ts.map +1 -0
- package/dist/neutral/Discount/Payload/Coupon/Coupons/FixedAmount.d.ts +26 -0
- package/dist/neutral/Discount/Payload/Coupon/Coupons/FixedAmount.d.ts.map +1 -0
- package/dist/neutral/Discount/Payload/Coupon/Coupons/FixedPercentage.d.ts +26 -0
- package/dist/neutral/Discount/Payload/Coupon/Coupons/FixedPercentage.d.ts.map +1 -0
- package/dist/neutral/Discount/Payload/Coupon/Coupons/FixedPrice.d.ts +26 -0
- package/dist/neutral/Discount/Payload/Coupon/Coupons/FixedPrice.d.ts.map +1 -0
- package/dist/neutral/Discount/Payload/Coupon/Coupons/index.d.ts +4 -0
- package/dist/neutral/Discount/Payload/Coupon/Coupons/index.d.ts.map +1 -0
- package/dist/neutral/Discount/Payload/Coupon/Payload.d.ts +16 -0
- package/dist/neutral/Discount/Payload/Coupon/Payload.d.ts.map +1 -0
- package/dist/neutral/Discount/Payload/Coupon/Schema.d.ts +5 -0
- package/dist/neutral/Discount/Payload/Coupon/Schema.d.ts.map +1 -0
- package/dist/neutral/Discount/Payload/Coupon/index.d.ts +6 -0
- package/dist/neutral/Discount/Payload/Coupon/index.d.ts.map +1 -0
- package/dist/neutral/Discount/Payload/Coupon/types/Condition.d.ts +16 -0
- package/dist/neutral/Discount/Payload/Coupon/types/Condition.d.ts.map +1 -0
- package/dist/neutral/Discount/Payload/Coupon/types/CouponFields.d.ts +16 -0
- package/dist/neutral/Discount/Payload/Coupon/types/CouponFields.d.ts.map +1 -0
- package/dist/neutral/Discount/Payload/Coupon/types/index.d.ts +4 -0
- package/dist/neutral/Discount/Payload/Coupon/types/index.d.ts.map +1 -0
- package/dist/neutral/Discount/Payload/Coupon/types/isStackable.d.ts +5 -0
- package/dist/neutral/Discount/Payload/Coupon/types/isStackable.d.ts.map +1 -0
- package/dist/neutral/Discount/Payload/Discount.d.ts +25 -0
- package/dist/neutral/Discount/Payload/Discount.d.ts.map +1 -0
- package/dist/neutral/Discount/Payload/NoDiscount.d.ts +3 -0
- package/dist/neutral/Discount/Payload/NoDiscount.d.ts.map +1 -0
- package/dist/neutral/Discount/Payload/index.d.ts +4 -0
- package/dist/neutral/Discount/Payload/index.d.ts.map +1 -0
- package/dist/neutral/Discount/index.d.ts +4 -0
- package/dist/neutral/Discount/index.d.ts.map +1 -0
- package/dist/neutral/Escrow/Outcome.d.ts +31 -0
- package/dist/neutral/Escrow/Outcome.d.ts.map +1 -0
- package/dist/neutral/Escrow/Schema.d.ts +5 -0
- package/dist/neutral/Escrow/Schema.d.ts.map +1 -0
- package/{src/Escrow/Terms/Party.ts → dist/neutral/Escrow/Terms/Party.d.ts} +3 -3
- package/dist/neutral/Escrow/Terms/Party.d.ts.map +1 -0
- package/dist/neutral/Escrow/Terms/PartySecret.d.ts +6 -0
- package/dist/neutral/Escrow/Terms/PartySecret.d.ts.map +1 -0
- package/dist/neutral/Escrow/Terms/Terms.d.ts +73 -0
- package/dist/neutral/Escrow/Terms/Terms.d.ts.map +1 -0
- package/dist/neutral/Escrow/Terms/index.d.ts +4 -0
- package/dist/neutral/Escrow/Terms/index.d.ts.map +1 -0
- package/dist/neutral/Escrow/index.d.ts +6 -0
- package/dist/neutral/Escrow/index.d.ts.map +1 -0
- package/dist/neutral/Escrow/util/appraisal/getAppraisalsByAsset.d.ts +12 -0
- package/dist/neutral/Escrow/util/appraisal/getAppraisalsByAsset.d.ts.map +1 -0
- package/dist/neutral/Escrow/util/appraisal/getSignaturesByAppraisal.d.ts +13 -0
- package/dist/neutral/Escrow/util/appraisal/getSignaturesByAppraisal.d.ts.map +1 -0
- package/dist/neutral/Escrow/util/appraisal/index.d.ts +3 -0
- package/dist/neutral/Escrow/util/appraisal/index.d.ts.map +1 -0
- package/dist/neutral/Escrow/util/index.d.ts +3 -0
- package/dist/neutral/Escrow/util/index.d.ts.map +1 -0
- package/dist/neutral/Escrow/util/secret/createEscrowIntent.d.ts +31 -0
- package/dist/neutral/Escrow/util/secret/createEscrowIntent.d.ts.map +1 -0
- package/dist/neutral/Escrow/util/secret/findEscrowPartySecretSignatures.d.ts +13 -0
- package/dist/neutral/Escrow/util/secret/findEscrowPartySecretSignatures.d.ts.map +1 -0
- package/dist/neutral/Escrow/util/secret/getEscrowSecret.d.ts +7 -0
- package/dist/neutral/Escrow/util/secret/getEscrowSecret.d.ts.map +1 -0
- package/dist/neutral/Escrow/util/secret/index.d.ts +5 -0
- package/dist/neutral/Escrow/util/secret/index.d.ts.map +1 -0
- package/dist/neutral/Escrow/util/secret/updateEscrowTermsWithSecret.d.ts +33 -0
- package/dist/neutral/Escrow/util/secret/updateEscrowTermsWithSecret.d.ts.map +1 -0
- package/dist/neutral/Escrow/validators/common/ModuleInstanceValidators/index.d.ts +2 -0
- package/dist/neutral/Escrow/validators/common/ModuleInstanceValidators/index.d.ts.map +1 -0
- package/dist/neutral/Escrow/validators/common/ModuleInstanceValidators/moduleInstanceValidators.d.ts +22 -0
- package/dist/neutral/Escrow/validators/common/ModuleInstanceValidators/moduleInstanceValidators.d.ts.map +1 -0
- package/dist/neutral/Escrow/validators/common/SecretValidators/getPartySecretSignedValidator.d.ts +10 -0
- package/dist/neutral/Escrow/validators/common/SecretValidators/getPartySecretSignedValidator.d.ts.map +1 -0
- package/dist/neutral/Escrow/validators/common/SecretValidators/index.d.ts +2 -0
- package/dist/neutral/Escrow/validators/common/SecretValidators/index.d.ts.map +1 -0
- package/dist/neutral/Escrow/validators/common/TemporalValidators/index.d.ts +2 -0
- package/dist/neutral/Escrow/validators/common/TemporalValidators/index.d.ts.map +1 -0
- package/dist/neutral/Escrow/validators/common/TemporalValidators/validateWithinWindow.d.ts +6 -0
- package/dist/neutral/Escrow/validators/common/TemporalValidators/validateWithinWindow.d.ts.map +1 -0
- package/dist/neutral/Escrow/validators/common/index.d.ts +4 -0
- package/dist/neutral/Escrow/validators/common/index.d.ts.map +1 -0
- package/dist/neutral/Escrow/validators/escrow/agent.d.ts +5 -0
- package/dist/neutral/Escrow/validators/escrow/agent.d.ts.map +1 -0
- package/dist/neutral/Escrow/validators/escrow/appraisal.d.ts +29 -0
- package/dist/neutral/Escrow/validators/escrow/appraisal.d.ts.map +1 -0
- package/dist/neutral/Escrow/validators/escrow/appraisalAuthorities.d.ts +10 -0
- package/dist/neutral/Escrow/validators/escrow/appraisalAuthorities.d.ts.map +1 -0
- package/dist/neutral/Escrow/validators/escrow/assets.d.ts +8 -0
- package/dist/neutral/Escrow/validators/escrow/assets.d.ts.map +1 -0
- package/dist/neutral/Escrow/validators/escrow/buyer.d.ts +8 -0
- package/dist/neutral/Escrow/validators/escrow/buyer.d.ts.map +1 -0
- package/dist/neutral/Escrow/validators/escrow/buyerSecret.d.ts +21 -0
- package/dist/neutral/Escrow/validators/escrow/buyerSecret.d.ts.map +1 -0
- package/dist/neutral/Escrow/validators/escrow/index.d.ts +11 -0
- package/dist/neutral/Escrow/validators/escrow/index.d.ts.map +1 -0
- package/dist/neutral/Escrow/validators/escrow/nbfExp.d.ts +4 -0
- package/dist/neutral/Escrow/validators/escrow/nbfExp.d.ts.map +1 -0
- package/dist/neutral/Escrow/validators/escrow/paymentAuthorities.d.ts +5 -0
- package/dist/neutral/Escrow/validators/escrow/paymentAuthorities.d.ts.map +1 -0
- package/dist/neutral/Escrow/validators/escrow/seller.d.ts +8 -0
- package/dist/neutral/Escrow/validators/escrow/seller.d.ts.map +1 -0
- package/dist/neutral/Escrow/validators/escrow/sellerSecret.d.ts +21 -0
- package/dist/neutral/Escrow/validators/escrow/sellerSecret.d.ts.map +1 -0
- package/dist/neutral/Escrow/validators/index.d.ts +3 -0
- package/dist/neutral/Escrow/validators/index.d.ts.map +1 -0
- package/dist/neutral/Invoice/Invoice.d.ts +17 -0
- package/dist/neutral/Invoice/Invoice.d.ts.map +1 -0
- package/dist/neutral/Invoice/index.d.ts +2 -0
- package/dist/neutral/Invoice/index.d.ts.map +1 -0
- package/dist/neutral/Payment/Instrument/Card/Payload.d.ts +44 -0
- package/dist/neutral/Payment/Instrument/Card/Payload.d.ts.map +1 -0
- package/dist/neutral/Payment/Instrument/Card/Schema.d.ts +5 -0
- package/dist/neutral/Payment/Instrument/Card/Schema.d.ts.map +1 -0
- package/dist/neutral/Payment/Instrument/Card/index.d.ts +3 -0
- package/dist/neutral/Payment/Instrument/Card/index.d.ts.map +1 -0
- package/dist/neutral/Payment/Instrument/Schema.d.ts +5 -0
- package/dist/neutral/Payment/Instrument/Schema.d.ts.map +1 -0
- package/dist/neutral/Payment/Instrument/index.d.ts +3 -0
- package/dist/neutral/Payment/Instrument/index.d.ts.map +1 -0
- package/dist/neutral/Payment/Payload.d.ts +30 -0
- package/dist/neutral/Payment/Payload.d.ts.map +1 -0
- package/dist/neutral/Payment/Schema.d.ts +5 -0
- package/dist/neutral/Payment/Schema.d.ts.map +1 -0
- package/dist/neutral/Payment/Status/Payload.d.ts +29 -0
- package/dist/neutral/Payment/Status/Payload.d.ts.map +1 -0
- package/dist/neutral/Payment/Status/Schema.d.ts +5 -0
- package/dist/neutral/Payment/Status/Schema.d.ts.map +1 -0
- package/dist/neutral/Payment/Status/index.d.ts +3 -0
- package/dist/neutral/Payment/Status/index.d.ts.map +1 -0
- package/dist/neutral/Payment/index.d.ts +5 -0
- package/dist/neutral/Payment/index.d.ts.map +1 -0
- package/dist/neutral/Purchase/Payload.d.ts +31 -0
- package/dist/neutral/Purchase/Payload.d.ts.map +1 -0
- package/dist/neutral/Purchase/Schema.d.ts +5 -0
- package/dist/neutral/Purchase/Schema.d.ts.map +1 -0
- package/dist/neutral/Purchase/index.d.ts +3 -0
- package/dist/neutral/Purchase/index.d.ts.map +1 -0
- package/dist/neutral/Receipt/Payload.d.ts +30 -0
- package/dist/neutral/Receipt/Payload.d.ts.map +1 -0
- package/dist/neutral/Receipt/Schema.d.ts +5 -0
- package/dist/neutral/Receipt/Schema.d.ts.map +1 -0
- package/dist/neutral/Receipt/index.d.ts +3 -0
- package/dist/neutral/Receipt/index.d.ts.map +1 -0
- package/dist/neutral/Schema.d.ts +5 -0
- package/dist/neutral/Schema.d.ts.map +1 -0
- package/dist/neutral/Subtotal/Diviner/Config.d.ts +10 -0
- package/dist/neutral/Subtotal/Diviner/Config.d.ts.map +1 -0
- package/dist/neutral/Subtotal/Diviner/Params.d.ts +5 -0
- package/dist/neutral/Subtotal/Diviner/Params.d.ts.map +1 -0
- package/dist/neutral/Subtotal/Diviner/Payload.d.ts +25 -0
- package/dist/neutral/Subtotal/Diviner/Payload.d.ts.map +1 -0
- package/dist/neutral/Subtotal/Diviner/index.d.ts +4 -0
- package/dist/neutral/Subtotal/Diviner/index.d.ts.map +1 -0
- package/dist/neutral/Subtotal/index.d.ts +2 -0
- package/dist/neutral/Subtotal/index.d.ts.map +1 -0
- package/dist/neutral/Total/Diviner/Config.d.ts +20 -0
- package/dist/neutral/Total/Diviner/Config.d.ts.map +1 -0
- package/dist/neutral/Total/Diviner/Params.d.ts +5 -0
- package/dist/neutral/Total/Diviner/Params.d.ts.map +1 -0
- package/dist/neutral/Total/Diviner/Payload.d.ts +25 -0
- package/dist/neutral/Total/Diviner/Payload.d.ts.map +1 -0
- package/dist/neutral/Total/Diviner/index.d.ts +4 -0
- package/dist/neutral/Total/Diviner/index.d.ts.map +1 -0
- package/dist/neutral/Total/index.d.ts +2 -0
- package/dist/neutral/Total/index.d.ts.map +1 -0
- package/dist/neutral/index.d.ts +12 -0
- package/dist/neutral/index.d.ts.map +1 -0
- package/dist/neutral/index.mjs +1097 -0
- package/dist/neutral/index.mjs.map +1 -0
- package/package.json +18 -6
- package/src/Amount/Iso4217Currency.ts +0 -557
- package/src/Amount/Payload.ts +0 -36
- package/src/Amount/index.ts +0 -2
- package/src/Billing/Address/Address.ts +0 -48
- package/src/Billing/Address/Schema.ts +0 -6
- package/src/Billing/Address/index.ts +0 -2
- package/src/Billing/Schema.ts +0 -6
- package/src/Billing/index.ts +0 -2
- package/src/Currency.ts +0 -3
- package/src/Discount/Config.ts +0 -35
- package/src/Discount/Params.ts +0 -14
- package/src/Discount/Payload/Coupon/Conditions/AppraisalAmountCondition.ts +0 -43
- package/src/Discount/Payload/Coupon/Conditions/AssetQuantityCondition.ts +0 -25
- package/src/Discount/Payload/Coupon/Conditions/BuyerCondition.ts +0 -50
- package/src/Discount/Payload/Coupon/Conditions/index.ts +0 -3
- package/src/Discount/Payload/Coupon/Coupons/FixedAmount.ts +0 -35
- package/src/Discount/Payload/Coupon/Coupons/FixedPercentage.ts +0 -36
- package/src/Discount/Payload/Coupon/Coupons/FixedPrice.ts +0 -35
- package/src/Discount/Payload/Coupon/Coupons/index.ts +0 -3
- package/src/Discount/Payload/Coupon/Payload.ts +0 -37
- package/src/Discount/Payload/Coupon/Schema.ts +0 -4
- package/src/Discount/Payload/Coupon/index.ts +0 -5
- package/src/Discount/Payload/Coupon/types/Condition.ts +0 -21
- package/src/Discount/Payload/Coupon/types/CouponFields.ts +0 -16
- package/src/Discount/Payload/Coupon/types/index.ts +0 -3
- package/src/Discount/Payload/Coupon/types/isStackable.ts +0 -6
- package/src/Discount/Payload/Discount.ts +0 -33
- package/src/Discount/Payload/NoDiscount.ts +0 -8
- package/src/Discount/Payload/index.ts +0 -3
- package/src/Discount/index.ts +0 -3
- package/src/Escrow/Outcome.ts +0 -42
- package/src/Escrow/Schema.ts +0 -4
- package/src/Escrow/Terms/PartySecret.ts +0 -6
- package/src/Escrow/Terms/Terms.ts +0 -82
- package/src/Escrow/Terms/index.ts +0 -3
- package/src/Escrow/index.ts +0 -5
- package/src/Escrow/util/appraisal/getAppraisalsByAsset.ts +0 -32
- package/src/Escrow/util/appraisal/getSignaturesByAppraisal.ts +0 -40
- package/src/Escrow/util/appraisal/index.ts +0 -2
- package/src/Escrow/util/index.ts +0 -2
- package/src/Escrow/util/secret/createEscrowIntent.ts +0 -17
- package/src/Escrow/util/secret/findEscrowPartySecretSignatures.ts +0 -47
- package/src/Escrow/util/secret/getEscrowSecret.ts +0 -11
- package/src/Escrow/util/secret/index.ts +0 -4
- package/src/Escrow/util/secret/updateEscrowTermsWithSecret.ts +0 -37
- package/src/Escrow/validators/common/ModuleInstanceValidators/index.ts +0 -1
- package/src/Escrow/validators/common/ModuleInstanceValidators/moduleInstanceValidators.ts +0 -48
- package/src/Escrow/validators/common/SecretValidators/getPartySecretSignedValidator.ts +0 -46
- package/src/Escrow/validators/common/SecretValidators/index.ts +0 -1
- package/src/Escrow/validators/common/TemporalValidators/index.ts +0 -1
- package/src/Escrow/validators/common/TemporalValidators/validateWithinWindow.ts +0 -6
- package/src/Escrow/validators/common/index.ts +0 -3
- package/src/Escrow/validators/escrow/agent.ts +0 -17
- package/src/Escrow/validators/escrow/appraisal.ts +0 -114
- package/src/Escrow/validators/escrow/appraisalAuthorities.ts +0 -37
- package/src/Escrow/validators/escrow/assets.ts +0 -19
- package/src/Escrow/validators/escrow/buyer.ts +0 -25
- package/src/Escrow/validators/escrow/buyerSecret.ts +0 -49
- package/src/Escrow/validators/escrow/index.ts +0 -10
- package/src/Escrow/validators/escrow/nbfExp.ts +0 -19
- package/src/Escrow/validators/escrow/paymentAuthorities.ts +0 -17
- package/src/Escrow/validators/escrow/seller.ts +0 -25
- package/src/Escrow/validators/escrow/sellerSecret.ts +0 -49
- package/src/Escrow/validators/index.ts +0 -2
- package/src/Invoice/Invoice.ts +0 -19
- package/src/Invoice/index.ts +0 -1
- package/src/Payment/Instrument/Card/Payload.ts +0 -50
- package/src/Payment/Instrument/Card/Schema.ts +0 -6
- package/src/Payment/Instrument/Card/index.ts +0 -2
- package/src/Payment/Instrument/Schema.ts +0 -6
- package/src/Payment/Instrument/index.ts +0 -2
- package/src/Payment/Payload.ts +0 -39
- package/src/Payment/Schema.ts +0 -6
- package/src/Payment/Status/Payload.ts +0 -39
- package/src/Payment/Status/Schema.ts +0 -6
- package/src/Payment/Status/index.ts +0 -2
- package/src/Payment/index.ts +0 -4
- package/src/Purchase/Payload.ts +0 -40
- package/src/Purchase/Schema.ts +0 -6
- package/src/Purchase/index.ts +0 -2
- package/src/Receipt/Payload.ts +0 -39
- package/src/Receipt/Schema.ts +0 -6
- package/src/Receipt/index.ts +0 -2
- package/src/Schema.ts +0 -4
- package/src/Subtotal/Diviner/Config.ts +0 -14
- package/src/Subtotal/Diviner/Params.ts +0 -8
- package/src/Subtotal/Diviner/Payload.ts +0 -33
- package/src/Subtotal/Diviner/index.ts +0 -3
- package/src/Subtotal/index.ts +0 -1
- package/src/Total/Diviner/Config.ts +0 -25
- package/src/Total/Diviner/Params.ts +0 -8
- package/src/Total/Diviner/Payload.ts +0 -33
- package/src/Total/Diviner/index.ts +0 -3
- package/src/Total/index.ts +0 -1
- package/src/index.ts +0 -11
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import type { Hash } from '@xylabs/sdk-js'
|
|
2
|
-
import type { BoundWitness } from '@xyo-network/boundwitness-model'
|
|
3
|
-
import { isBoundWitness } from '@xyo-network/boundwitness-model'
|
|
4
|
-
import type { Payload } from '@xyo-network/payload-model'
|
|
5
|
-
|
|
6
|
-
import type {
|
|
7
|
-
EscrowParty, EscrowPartySecret, EscrowTerms,
|
|
8
|
-
} from '../../Terms/index.ts'
|
|
9
|
-
/**
|
|
10
|
-
* Returns the log prefix for the party
|
|
11
|
-
* @param party The party
|
|
12
|
-
* @returns The log prefix for the party
|
|
13
|
-
*/
|
|
14
|
-
const getLogPrefix = (party: EscrowParty) => {
|
|
15
|
-
const partySecret: EscrowPartySecret = party === 'seller' ? 'sellerSecret' : 'buyerSecret'
|
|
16
|
-
return `EscrowTerms.${partySecret}`
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Returns an array of BoundWitnesses containing the secret signed by all the parties
|
|
21
|
-
* @param terms The escrow terms
|
|
22
|
-
* @param dictionary A dictionary of all the payloads associated with the escrow
|
|
23
|
-
* @param party The party to get the secret signatures for
|
|
24
|
-
* @returns An array of BoundWitnesses containing the secret signed by all the parties
|
|
25
|
-
*/
|
|
26
|
-
export const findEscrowPartySecretSignatures = (terms: EscrowTerms, dictionary: Record<Hash, Payload>, party: EscrowParty): BoundWitness[] => {
|
|
27
|
-
const partyAddresses = terms[party]
|
|
28
|
-
if (partyAddresses === undefined || partyAddresses.length === 0) {
|
|
29
|
-
console.log(`${getLogPrefix(party)}: No ${party}: ${terms[party]}`)
|
|
30
|
-
return []
|
|
31
|
-
}
|
|
32
|
-
const partySecret: EscrowPartySecret = party === 'seller' ? 'sellerSecret' : 'buyerSecret'
|
|
33
|
-
const secretHash = terms[partySecret]
|
|
34
|
-
if (secretHash === undefined) {
|
|
35
|
-
console.log(`${getLogPrefix(party)}: No ${partySecret}: ${terms[partySecret]}`)
|
|
36
|
-
return []
|
|
37
|
-
}
|
|
38
|
-
// BWs containing the secret signed by all the parties
|
|
39
|
-
const partySignedBWs = Object.values(dictionary)
|
|
40
|
-
// Find all BoundWitnesses
|
|
41
|
-
.filter(isBoundWitness)
|
|
42
|
-
// That contain the seller secret
|
|
43
|
-
.filter(bw => bw.payload_hashes.includes(secretHash))
|
|
44
|
-
// That are signed by all the parties
|
|
45
|
-
.filter(bw => partyAddresses.every(address => bw.addresses.includes(address)))
|
|
46
|
-
return partySignedBWs
|
|
47
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Crypto } from '@xylabs/crypto'
|
|
2
|
-
import type { Id } from '@xyo-network/id-payload-plugin'
|
|
3
|
-
import { IdSchema } from '@xyo-network/id-payload-plugin'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Returns a cryptographically random secret to use for escrow
|
|
7
|
-
* @returns The escrow secret
|
|
8
|
-
*/
|
|
9
|
-
export const getEscrowSecret = (): Id => {
|
|
10
|
-
return { salt: Crypto.randomUUID(), schema: IdSchema }
|
|
11
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { AccountInstance } from '@xyo-network/account-model'
|
|
2
|
-
import { BoundWitnessBuilder } from '@xyo-network/boundwitness-builder'
|
|
3
|
-
import type { Id } from '@xyo-network/id-payload-plugin'
|
|
4
|
-
import { PayloadBuilder } from '@xyo-network/sdk-js'
|
|
5
|
-
|
|
6
|
-
import type {
|
|
7
|
-
EscrowParty, EscrowPartySecret, EscrowTerms,
|
|
8
|
-
} from '../../Terms/index.ts'
|
|
9
|
-
import { getEscrowSecret } from './getEscrowSecret.ts'
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Creates an escrow intent (for a buyer or seller) using the supplied secret
|
|
13
|
-
* @param terms The payload describing the terms for the escrow
|
|
14
|
-
* @param escrowParty The party in the escrow transaction
|
|
15
|
-
* @param account The account(s) to create the escrow intent with
|
|
16
|
-
* @param secret The secret for the escrow principal party to use for the escrow. If
|
|
17
|
-
* not provided, a cryptographically random secret will be generated.
|
|
18
|
-
* @returns The escrow intent
|
|
19
|
-
*/
|
|
20
|
-
export const updateEscrowTermsWithSecret = async (
|
|
21
|
-
terms: EscrowTerms,
|
|
22
|
-
escrowParty: EscrowParty,
|
|
23
|
-
account: AccountInstance | AccountInstance[],
|
|
24
|
-
secret?: Id,
|
|
25
|
-
) => {
|
|
26
|
-
if (!secret) secret = getEscrowSecret()
|
|
27
|
-
const signers = Array.isArray(account) ? account : [account]
|
|
28
|
-
// Add party addresses to escrow terms
|
|
29
|
-
terms[escrowParty] = signers.map(signer => signer.address)
|
|
30
|
-
// Add secret hash to terms
|
|
31
|
-
const secretType: EscrowPartySecret = escrowParty === 'buyer' ? 'buyerSecret' : 'sellerSecret'
|
|
32
|
-
const secretHash = await PayloadBuilder.dataHash(secret)
|
|
33
|
-
terms[secretType] = secretHash
|
|
34
|
-
// Have the parties sign the secret and terms
|
|
35
|
-
const result = await new BoundWitnessBuilder().signers(signers).payloads([terms, secret]).build()
|
|
36
|
-
return result
|
|
37
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './moduleInstanceValidators.ts'
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import type { ModuleIdentifier } from '@xyo-network/module-model'
|
|
2
|
-
import type { PayloadValueExpression } from '@xyo-network/payload-model'
|
|
3
|
-
|
|
4
|
-
import type { EscrowTerms } from '../../../Terms/index.ts'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Checks if property value of the escrow terms contains one of the valid moduleIdentifiers
|
|
8
|
-
* @param escrowTerms The escrow terms to validate
|
|
9
|
-
* @param propertyExpression The selector to get the property containing the moduleIdentifier(s) from the escrow terms
|
|
10
|
-
* @param moduleIdentifiers The list of allowed moduleIdentifiers
|
|
11
|
-
* @param required Is the property required to be present
|
|
12
|
-
* @returns True if the property value contains one of the valid moduleIdentifiers
|
|
13
|
-
*/
|
|
14
|
-
export const moduleIdentifiersContainsOneOf = (
|
|
15
|
-
escrowTerms: EscrowTerms,
|
|
16
|
-
propertyExpression: PayloadValueExpression<EscrowTerms, 'appraisalAuthorities' | 'buyer' | 'escrowAgent' | 'paymentAuthorities' | 'seller'>,
|
|
17
|
-
moduleIdentifiers: ModuleIdentifier[],
|
|
18
|
-
required: boolean = true,
|
|
19
|
-
) => {
|
|
20
|
-
const termsValue: string | string[] | undefined = propertyExpression(escrowTerms)
|
|
21
|
-
if (termsValue === undefined) {
|
|
22
|
-
return required ? false : true
|
|
23
|
-
} else {
|
|
24
|
-
return Array.isArray(termsValue) ? termsValue.some(address => moduleIdentifiers.includes(address)) : moduleIdentifiers.includes(termsValue)
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Checks if property value of the escrow terms contains all of the valid moduleIdentifiers
|
|
30
|
-
* @param escrowTerms The escrow terms to validate
|
|
31
|
-
* @param selector The selector to get the property containing the moduleIdentifier(s) from the escrow terms
|
|
32
|
-
* @param moduleIdentifiers The list of allowed moduleIdentifiers
|
|
33
|
-
* @param required Is the property required to be present
|
|
34
|
-
* @returns True if the property value contains all of the valid moduleIdentifiers
|
|
35
|
-
*/
|
|
36
|
-
export const moduleIdentifiersContainsAllOf = (
|
|
37
|
-
escrowTerms: EscrowTerms,
|
|
38
|
-
selector: PayloadValueExpression<EscrowTerms, 'appraisalAuthorities' | 'buyer' | 'escrowAgent' | 'paymentAuthorities' | 'seller'>,
|
|
39
|
-
moduleIdentifiers: ModuleIdentifier[],
|
|
40
|
-
required: boolean = true,
|
|
41
|
-
) => {
|
|
42
|
-
const termsValue: string | string[] | undefined = selector(escrowTerms)
|
|
43
|
-
if (termsValue === undefined) {
|
|
44
|
-
return required ? false : true
|
|
45
|
-
} else {
|
|
46
|
-
return Array.isArray(termsValue) ? termsValue.every(address => moduleIdentifiers.includes(address)) : moduleIdentifiers.includes(termsValue)
|
|
47
|
-
}
|
|
48
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import type { Hash } from '@xylabs/sdk-js'
|
|
2
|
-
import { BoundWitnessValidator } from '@xyo-network/boundwitness-validator'
|
|
3
|
-
import type { AsyncPayloadValidationFunction, Payload } from '@xyo-network/payload-model'
|
|
4
|
-
|
|
5
|
-
import type {
|
|
6
|
-
EscrowParty, EscrowPartySecret, EscrowTerms,
|
|
7
|
-
} from '../../../Terms/index.ts'
|
|
8
|
-
import { findEscrowPartySecretSignatures } from '../../../util/index.ts'
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Returns the log prefix for the party
|
|
12
|
-
* @param party The party
|
|
13
|
-
* @returns The log prefix for the party
|
|
14
|
-
*/
|
|
15
|
-
const getLogPrefix = (party: EscrowParty) => {
|
|
16
|
-
const partySecret: EscrowPartySecret = party === 'seller' ? 'sellerSecret' : 'buyerSecret'
|
|
17
|
-
return `EscrowTerms.${partySecret}`
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Returns a function that validates the escrow terms for the existence of the party secret signed by the party
|
|
22
|
-
* @param dictionary Payload dictionary of the escrow terms
|
|
23
|
-
* @returns A function that validates the escrow terms for the existence of the party secret signed by the party
|
|
24
|
-
*/
|
|
25
|
-
export const getPartySecretSignedValidator = (dictionary: Record<Hash, Payload>, party: EscrowParty): AsyncPayloadValidationFunction<EscrowTerms> => {
|
|
26
|
-
const partySecret: EscrowPartySecret = party === 'seller' ? 'sellerSecret' : 'buyerSecret'
|
|
27
|
-
return async (terms: EscrowTerms): Promise<boolean> => {
|
|
28
|
-
// Party-signed party secret BWs
|
|
29
|
-
const buyerSecretBWs = findEscrowPartySecretSignatures(terms, dictionary, party)
|
|
30
|
-
|
|
31
|
-
// If there are no BWs, return false
|
|
32
|
-
if (buyerSecretBWs.length === 0) {
|
|
33
|
-
console.log(`${getLogPrefix(party)}: No BoundWitnesses supplied for ${partySecret}: ${terms[partySecret]}`)
|
|
34
|
-
return false
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Ensure each BW supplied for the party secret is valid
|
|
38
|
-
const errors = await Promise.all(buyerSecretBWs.map(bw => new BoundWitnessValidator(bw).validate()))
|
|
39
|
-
const validBoundWitnesses = errors.every(errors => errors.length === 0)
|
|
40
|
-
if (!validBoundWitnesses) {
|
|
41
|
-
console.log(`${getLogPrefix(party)}: Invalid BoundWitnesses supplied for ${partySecret}: ${terms[partySecret]}`)
|
|
42
|
-
return false
|
|
43
|
-
}
|
|
44
|
-
return true
|
|
45
|
-
}
|
|
46
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './getPartySecretSignedValidator.ts'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './validateWithinWindow.ts'
|
|
@@ -1,6 +0,0 @@
|
|
|
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
|
-
return !(value.exp === undefined || value.exp < exp)
|
|
6
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { ModuleIdentifier } from '@xyo-network/module-model'
|
|
2
|
-
import type { SyncPayloadValidationFunction } from '@xyo-network/payload-model'
|
|
3
|
-
|
|
4
|
-
import type { EscrowTerms } from '../../Terms/index.ts'
|
|
5
|
-
import { moduleIdentifiersContainsOneOf } from '../common/index.ts'
|
|
6
|
-
|
|
7
|
-
const name = 'EscrowTerms.escrowAgent'
|
|
8
|
-
|
|
9
|
-
export const getEscrowAgentAllowedValidator = (allowedEscrowAgent: ModuleIdentifier): SyncPayloadValidationFunction<EscrowTerms> => {
|
|
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
|
-
}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import type { Hash } from '@xylabs/sdk-js'
|
|
2
|
-
import { assertEx } from '@xylabs/sdk-js'
|
|
3
|
-
import type { BoundWitness } from '@xyo-network/boundwitness-model'
|
|
4
|
-
import { isBoundWitness } from '@xyo-network/boundwitness-model'
|
|
5
|
-
import type { HashLeaseEstimate } from '@xyo-network/diviner-hash-lease'
|
|
6
|
-
import type {
|
|
7
|
-
Payload, SyncPayloadValidationFunction, WithSources,
|
|
8
|
-
} from '@xyo-network/payload-model'
|
|
9
|
-
|
|
10
|
-
import type { EscrowTerms } from '../../Terms/index.ts'
|
|
11
|
-
import { getAppraisalsByAsset } from '../../util/index.ts'
|
|
12
|
-
import { validateWithinWindow } from '../common/index.ts'
|
|
13
|
-
|
|
14
|
-
const name = 'EscrowTerms.appraisal'
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* A function that validates the escrow terms for tbe existence of appraisals
|
|
18
|
-
* @returns True if the escrow terms contain appraisals, false otherwise
|
|
19
|
-
*/
|
|
20
|
-
export const appraisalsExistValidator: SyncPayloadValidationFunction<EscrowTerms> = (terms: EscrowTerms) => {
|
|
21
|
-
// Validate we have appraisals
|
|
22
|
-
const appraisals = terms.appraisals
|
|
23
|
-
if (!appraisals || appraisals.length === 0) {
|
|
24
|
-
console.log(`${name}: No appraisals: ${terms.appraisals}`)
|
|
25
|
-
return false
|
|
26
|
-
}
|
|
27
|
-
return true
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Returns a function that validates the escrow terms for appraisals which are from valid authorities
|
|
32
|
-
* @param dictionary Payload dictionary of the escrow terms
|
|
33
|
-
* @returns A function that validates the escrow terms for appraisals which are from valid authorities
|
|
34
|
-
*/
|
|
35
|
-
export const getAppraisalsFromValidAuthoritiesValidator = (dictionary: Record<Hash, Payload>): SyncPayloadValidationFunction<EscrowTerms> => {
|
|
36
|
-
return (terms: EscrowTerms) => {
|
|
37
|
-
const appraisals = assertEx(terms.appraisals, () => `${name}: No appraisals: ${terms.appraisals}`)
|
|
38
|
-
const appraisalAuthorities = assertEx(terms.appraisalAuthorities, () => `${name}: No appraisalAuthorities: ${terms.appraisalAuthorities}`)
|
|
39
|
-
|
|
40
|
-
// Validate the appraisals are signed by valid appraisal authorities. Validation criteria:
|
|
41
|
-
// - We have a bw for each of the appraisal
|
|
42
|
-
// - The bw is signed by an approved appraisal authority
|
|
43
|
-
const appraisalBWsValid: Record<Hash, BoundWitness[]> = Object.fromEntries(
|
|
44
|
-
appraisals.map<[Hash, BoundWitness[]]>(hash => [hash, []]),
|
|
45
|
-
)
|
|
46
|
-
for (const bw of Object.values(dictionary).filter(isBoundWitness)) {
|
|
47
|
-
for (const appraisal of appraisals) {
|
|
48
|
-
if (bw.payload_hashes.includes(appraisal) && bw.addresses.some(address => appraisalAuthorities.includes(address))) {
|
|
49
|
-
appraisalBWsValid[appraisal].push(bw)
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
for (const [appraisal, bws] of Object.entries(appraisalBWsValid)) {
|
|
54
|
-
if (bws.length === 0) {
|
|
55
|
-
console.log(`${name}: No valid appraisals for ${appraisal}`)
|
|
56
|
-
return false
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return true
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Returns a function that validates the escrow terms for appraisals which are valid
|
|
65
|
-
* @param dictionary Payload dictionary of the escrow terms
|
|
66
|
-
* @param minimumExp The minium amount of time an estimate needs to be valid
|
|
67
|
-
* for in the future (so as not to expire before the escrow is complete)
|
|
68
|
-
* @returns A function that validates the escrow terms for appraisals which are valid
|
|
69
|
-
*/
|
|
70
|
-
export const getAppraisalsValidValidator = (
|
|
71
|
-
dictionary: Record<Hash, Payload>,
|
|
72
|
-
minimumExp: number,
|
|
73
|
-
): SyncPayloadValidationFunction<EscrowTerms> => {
|
|
74
|
-
return (terms: EscrowTerms) => {
|
|
75
|
-
// Verify we have an estimate for each of the assets
|
|
76
|
-
const estimatesByAsset = getAppraisalsByAsset(terms, dictionary)
|
|
77
|
-
// Validate each of the estimates are valid (time, price, etc)
|
|
78
|
-
const now = Date.now()
|
|
79
|
-
const exp = now + minimumExp
|
|
80
|
-
for (const [asset, estimates] of Object.entries(estimatesByAsset)) {
|
|
81
|
-
for (const estimate of estimates) {
|
|
82
|
-
if (!validateEstimate(estimate, exp)) {
|
|
83
|
-
console.log(`${name}: Invalid estimate for asset ${asset}: ${estimate}`)
|
|
84
|
-
return false
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return true
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Returns a function that validates the escrow terms to ensure that they contain an appraisal for each asset
|
|
94
|
-
* @param dictionary Payload dictionary of the escrow terms
|
|
95
|
-
* @returns A function that validates the escrow terms for appraisals
|
|
96
|
-
*/
|
|
97
|
-
export const getAppraisalsForAllAssetsValidator = (dictionary: Record<Hash, Payload>): SyncPayloadValidationFunction<EscrowTerms> => {
|
|
98
|
-
return (terms: EscrowTerms) => {
|
|
99
|
-
// Verify we have an estimate for each of the assets
|
|
100
|
-
const assets = assertEx(terms.assets, () => `${name}: No assets: ${terms.assets}`)
|
|
101
|
-
const estimatesByAsset = getAppraisalsByAsset(terms, dictionary)
|
|
102
|
-
if (Object.keys(estimatesByAsset).length !== assets.length) {
|
|
103
|
-
console.log(`${name}: Missing appraisals for all assets: ${assets}`)
|
|
104
|
-
return false
|
|
105
|
-
}
|
|
106
|
-
return true
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const validateEstimate = (estimate: WithSources<HashLeaseEstimate>, exp: number): boolean => {
|
|
111
|
-
if (!validateWithinWindow(estimate, exp)) return false
|
|
112
|
-
if (estimate.currency !== 'USD') return false
|
|
113
|
-
return (estimate.price >= 0)
|
|
114
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { asAddress } from '@xylabs/sdk-js'
|
|
2
|
-
import type { ModuleIdentifier } from '@xyo-network/module-model'
|
|
3
|
-
import type { SyncPayloadValidationFunction } from '@xyo-network/payload-model'
|
|
4
|
-
|
|
5
|
-
import type { EscrowTerms } from '../../Terms/index.ts'
|
|
6
|
-
import { moduleIdentifiersContainsAllOf } from '../common/index.ts'
|
|
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: SyncPayloadValidationFunction<EscrowTerms> = (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[]): SyncPayloadValidationFunction<EscrowTerms> => {
|
|
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
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { SyncPayloadValidationFunction } from '@xyo-network/payload-model'
|
|
2
|
-
|
|
3
|
-
import type { EscrowTerms } from '../../Terms/index.ts'
|
|
4
|
-
|
|
5
|
-
const name = 'EscrowTerms.assets'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Returns a function that validates the escrow terms for assets
|
|
9
|
-
* @returns A function that validates the escrow terms for assets
|
|
10
|
-
*/
|
|
11
|
-
export const assetsExistValidator: SyncPayloadValidationFunction<EscrowTerms> = (terms: EscrowTerms) => {
|
|
12
|
-
// Validate we have assets
|
|
13
|
-
const assets = terms.assets
|
|
14
|
-
if (!assets || assets.length === 0) {
|
|
15
|
-
console.log(`${name}: No assets: ${terms.assets}`)
|
|
16
|
-
return false
|
|
17
|
-
}
|
|
18
|
-
return true
|
|
19
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { asAddress } from '@xylabs/sdk-js'
|
|
2
|
-
import type { SyncPayloadValidationFunction } from '@xyo-network/payload-model'
|
|
3
|
-
|
|
4
|
-
import type { EscrowTerms } from '../../Terms/index.ts'
|
|
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: SyncPayloadValidationFunction<EscrowTerms> = (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
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { Hash } from '@xylabs/sdk-js'
|
|
2
|
-
import { assertEx } from '@xylabs/sdk-js'
|
|
3
|
-
import type {
|
|
4
|
-
AsyncPayloadValidationFunction, Payload, SyncPayloadValidationFunction,
|
|
5
|
-
} from '@xyo-network/payload-model'
|
|
6
|
-
|
|
7
|
-
import type { EscrowTerms } from '../../Terms/index.ts'
|
|
8
|
-
import { getPartySecretSignedValidator } from '../common/index.ts'
|
|
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: SyncPayloadValidationFunction<EscrowTerms> = (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, Payload>): SyncPayloadValidationFunction<EscrowTerms> => {
|
|
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, Payload>): AsyncPayloadValidationFunction<EscrowTerms> => {
|
|
48
|
-
return getPartySecretSignedValidator(dictionary, 'buyer')
|
|
49
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export * from './agent.ts'
|
|
2
|
-
export * from './appraisal.ts'
|
|
3
|
-
export * from './appraisalAuthorities.ts'
|
|
4
|
-
export * from './assets.ts'
|
|
5
|
-
export * from './buyer.ts'
|
|
6
|
-
export * from './buyerSecret.ts'
|
|
7
|
-
export * from './nbfExp.ts'
|
|
8
|
-
export * from './paymentAuthorities.ts'
|
|
9
|
-
export * from './seller.ts'
|
|
10
|
-
export * from './sellerSecret.ts'
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { SyncPayloadValidationFunction } from '@xyo-network/payload-model'
|
|
2
|
-
|
|
3
|
-
import type { EscrowTerms } from '../../Terms/index.ts'
|
|
4
|
-
|
|
5
|
-
export const getNbfExpValidator = (now: number, minRequiredDuration: number): SyncPayloadValidationFunction<EscrowTerms> => {
|
|
6
|
-
const minExp = now + minRequiredDuration
|
|
7
|
-
return (terms: EscrowTerms) => {
|
|
8
|
-
const { exp, nbf } = terms
|
|
9
|
-
if (nbf === undefined || nbf < now) {
|
|
10
|
-
console.log(`EscrowTerms.nbf: invalid nbf ${terms.nbf}`)
|
|
11
|
-
return false
|
|
12
|
-
}
|
|
13
|
-
if (exp === undefined || exp < minExp || nbf > exp) {
|
|
14
|
-
console.log(`EscrowTerms.exp: invalid exp ${terms.exp}`)
|
|
15
|
-
return false
|
|
16
|
-
}
|
|
17
|
-
return true
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { ModuleIdentifier } from '@xyo-network/module-model'
|
|
2
|
-
import type { SyncPayloadValidationFunction } from '@xyo-network/payload-model'
|
|
3
|
-
|
|
4
|
-
import type { EscrowTerms } from '../../Terms/index.ts'
|
|
5
|
-
import { moduleIdentifiersContainsAllOf } from '../common/index.ts'
|
|
6
|
-
|
|
7
|
-
const name = 'EscrowTerms.paymentAuthorities'
|
|
8
|
-
|
|
9
|
-
export const getPaymentAuthoritiesAllowedValidator = (allowed: ModuleIdentifier[]): SyncPayloadValidationFunction<EscrowTerms> => {
|
|
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
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { asAddress } from '@xylabs/sdk-js'
|
|
2
|
-
import type { SyncPayloadValidationFunction } from '@xyo-network/payload-model'
|
|
3
|
-
|
|
4
|
-
import type { EscrowTerms } from '../../Terms/index.ts'
|
|
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: SyncPayloadValidationFunction<EscrowTerms> = (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
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { Hash } from '@xylabs/sdk-js'
|
|
2
|
-
import { assertEx } from '@xylabs/sdk-js'
|
|
3
|
-
import type {
|
|
4
|
-
AsyncPayloadValidationFunction, Payload, SyncPayloadValidationFunction,
|
|
5
|
-
} from '@xyo-network/payload-model'
|
|
6
|
-
|
|
7
|
-
import type { EscrowTerms } from '../../Terms/index.ts'
|
|
8
|
-
import { getPartySecretSignedValidator } from '../common/index.ts'
|
|
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: SyncPayloadValidationFunction<EscrowTerms> = (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, Payload>): SyncPayloadValidationFunction<EscrowTerms> => {
|
|
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, Payload>): AsyncPayloadValidationFunction<EscrowTerms> => {
|
|
48
|
-
return getPartySecretSignedValidator(dictionary, 'seller')
|
|
49
|
-
}
|
package/src/Invoice/Invoice.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { Discount } from '../Discount/index.ts'
|
|
2
|
-
import type { Payment } from '../Payment/index.ts'
|
|
3
|
-
import type { Subtotal } from '../Subtotal/index.ts'
|
|
4
|
-
import type { Total } from '../Total/index.ts'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* A tuple containing the subtotal, total, and payment for an invoice.
|
|
8
|
-
*/
|
|
9
|
-
export type StandardInvoice = [Subtotal, Total, Payment]
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* A tuple containing the subtotal, total, payment, and discount for an invoice.
|
|
13
|
-
*/
|
|
14
|
-
export type DiscountedInvoice = [...StandardInvoice, Discount]
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* An invoice.
|
|
18
|
-
*/
|
|
19
|
-
export type Invoice = StandardInvoice | DiscountedInvoice
|
package/src/Invoice/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './Invoice.ts'
|