@xyo-network/payment-payload-plugins 5.3.1 → 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/Payload.d.ts +2 -2
- package/dist/neutral/Billing/Address/Address.d.ts +2 -2
- package/dist/neutral/Discount/Config.d.ts +1 -1
- package/dist/neutral/Discount/Config.d.ts.map +1 -1
- package/dist/neutral/Discount/Params.d.ts +1 -1
- package/dist/neutral/Discount/Params.d.ts.map +1 -1
- package/dist/neutral/Discount/Payload/Coupon/Conditions/BuyerCondition.d.ts +1 -1
- package/dist/neutral/Discount/Payload/Coupon/Conditions/BuyerCondition.d.ts.map +1 -1
- package/dist/neutral/Discount/Payload/Coupon/Coupons/FixedAmount.d.ts +2 -2
- package/dist/neutral/Discount/Payload/Coupon/Coupons/FixedPercentage.d.ts +2 -2
- package/dist/neutral/Discount/Payload/Coupon/Coupons/FixedPrice.d.ts +2 -2
- package/dist/neutral/Discount/Payload/Coupon/Payload.d.ts +2 -2
- package/dist/neutral/Discount/Payload/Coupon/types/Condition.d.ts +2 -2
- package/dist/neutral/Discount/Payload/Coupon/types/CouponFields.d.ts +1 -1
- package/dist/neutral/Discount/Payload/Coupon/types/CouponFields.d.ts.map +1 -1
- package/dist/neutral/Discount/Payload/Discount.d.ts +2 -2
- package/dist/neutral/Escrow/Outcome.d.ts +2 -2
- package/dist/neutral/Escrow/Outcome.d.ts.map +1 -1
- package/dist/neutral/Escrow/Terms/Terms.d.ts +3 -3
- package/dist/neutral/Escrow/Terms/Terms.d.ts.map +1 -1
- package/dist/neutral/Escrow/util/appraisal/getAppraisalsByAsset.d.ts +1 -1
- package/dist/neutral/Escrow/util/appraisal/getAppraisalsByAsset.d.ts.map +1 -1
- package/dist/neutral/Escrow/util/appraisal/getSignaturesByAppraisal.d.ts +1 -1
- package/dist/neutral/Escrow/util/appraisal/getSignaturesByAppraisal.d.ts.map +1 -1
- package/dist/neutral/Escrow/util/secret/findEscrowPartySecretSignatures.d.ts +1 -1
- package/dist/neutral/Escrow/util/secret/findEscrowPartySecretSignatures.d.ts.map +1 -1
- package/dist/neutral/Escrow/util/secret/updateEscrowTermsWithSecret.d.ts +3 -3
- package/dist/neutral/Escrow/util/secret/updateEscrowTermsWithSecret.d.ts.map +1 -1
- package/dist/neutral/Escrow/validators/common/SecretValidators/getPartySecretSignedValidator.d.ts +1 -1
- package/dist/neutral/Escrow/validators/common/SecretValidators/getPartySecretSignedValidator.d.ts.map +1 -1
- package/dist/neutral/Escrow/validators/escrow/appraisal.d.ts +1 -1
- package/dist/neutral/Escrow/validators/escrow/appraisal.d.ts.map +1 -1
- package/dist/neutral/Escrow/validators/escrow/buyerSecret.d.ts +1 -1
- package/dist/neutral/Escrow/validators/escrow/buyerSecret.d.ts.map +1 -1
- package/dist/neutral/Escrow/validators/escrow/sellerSecret.d.ts +1 -1
- package/dist/neutral/Escrow/validators/escrow/sellerSecret.d.ts.map +1 -1
- package/dist/neutral/Payment/Instrument/Card/Payload.d.ts +2 -2
- package/dist/neutral/Payment/Payload.d.ts +2 -2
- package/dist/neutral/Payment/Status/Payload.d.ts +2 -2
- package/dist/neutral/Purchase/Payload.d.ts +3 -3
- package/dist/neutral/Purchase/Payload.d.ts.map +1 -1
- package/dist/neutral/Receipt/Payload.d.ts +2 -2
- package/dist/neutral/Subtotal/Diviner/Payload.d.ts +2 -2
- package/dist/neutral/Total/Diviner/Payload.d.ts +2 -2
- package/dist/neutral/index.mjs +24 -24
- package/dist/neutral/index.mjs.map +1 -1
- package/package.json +39 -27
- 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/Party.ts +0 -6
- 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,43 +0,0 @@
|
|
|
1
|
-
/* eslint-disable unicorn/no-thenable */
|
|
2
|
-
import { SchemaSchema } from '@xyo-network/schema-payload-plugin'
|
|
3
|
-
|
|
4
|
-
import type { Condition } from '../types/index.ts'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Creates a coupon condition that requires an appraisal amount below a certain value
|
|
8
|
-
* @param maximumAppraisalAmount The maximum appraisal amount
|
|
9
|
-
* @returns A condition that requires an appraisal amount below a certain value
|
|
10
|
-
*/
|
|
11
|
-
export const createConditionForMaximumAppraisalAmount = (maximumAppraisalAmount: number): Condition => {
|
|
12
|
-
return {
|
|
13
|
-
schema: SchemaSchema,
|
|
14
|
-
definition: {
|
|
15
|
-
allOf: [
|
|
16
|
-
{
|
|
17
|
-
type: 'array',
|
|
18
|
-
contains: {
|
|
19
|
-
type: 'object',
|
|
20
|
-
properties: {
|
|
21
|
-
schema: { type: 'string', const: 'network.xyo.escrow.terms' },
|
|
22
|
-
appraisals: { type: 'array', minItems: 1 },
|
|
23
|
-
},
|
|
24
|
-
required: ['schema', 'appraisals'],
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
type: 'array',
|
|
29
|
-
contains: {
|
|
30
|
-
type: 'object',
|
|
31
|
-
properties: { schema: { type: 'string', const: 'network.xyo.hash.lease.estimate' } },
|
|
32
|
-
required: ['schema'],
|
|
33
|
-
},
|
|
34
|
-
items: {
|
|
35
|
-
type: 'object',
|
|
36
|
-
if: { properties: { schema: { type: 'string', const: 'network.xyo.hash.lease.estimate' } } },
|
|
37
|
-
then: { properties: { price: { type: 'number', maximum: maximumAppraisalAmount } }, required: ['price'] },
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
],
|
|
41
|
-
},
|
|
42
|
-
}
|
|
43
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { SchemaSchema } from '@xyo-network/schema-payload-plugin'
|
|
2
|
-
|
|
3
|
-
import type { Condition } from '../types/index.ts'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Returns a coupon condition that requires a minimum quantity of assets
|
|
7
|
-
* @param minimumAssetQuantity The minimum quantity of assets required
|
|
8
|
-
* @returns A condition that requires a minimum quantity of assets
|
|
9
|
-
*/
|
|
10
|
-
export const createConditionForMinimumAssetQuantity = (minimumAssetQuantity: number): Condition => {
|
|
11
|
-
return {
|
|
12
|
-
schema: SchemaSchema,
|
|
13
|
-
definition: {
|
|
14
|
-
type: 'array',
|
|
15
|
-
contains: {
|
|
16
|
-
type: 'object',
|
|
17
|
-
properties: {
|
|
18
|
-
schema: { type: 'string', const: 'network.xyo.escrow.terms' },
|
|
19
|
-
assets: { type: 'array', minItems: minimumAssetQuantity },
|
|
20
|
-
},
|
|
21
|
-
required: ['schema', 'assets'],
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import type { Address } from '@xylabs/hex'
|
|
2
|
-
import { SchemaSchema } from '@xyo-network/schema-payload-plugin'
|
|
3
|
-
|
|
4
|
-
import type { Condition } from '../types/index.ts'
|
|
5
|
-
|
|
6
|
-
export type BuyerCondition = Condition & {
|
|
7
|
-
definition: {
|
|
8
|
-
contains: {
|
|
9
|
-
properties: {
|
|
10
|
-
buyer: {
|
|
11
|
-
items: {
|
|
12
|
-
const: Address
|
|
13
|
-
type: 'string'
|
|
14
|
-
}
|
|
15
|
-
minItems: 1
|
|
16
|
-
type: 'array'
|
|
17
|
-
}
|
|
18
|
-
schema: { const: 'network.xyo.escrow.terms'; type: 'string' }
|
|
19
|
-
}
|
|
20
|
-
required: ['schema', 'buyer']
|
|
21
|
-
type: 'object'
|
|
22
|
-
}
|
|
23
|
-
type: 'array'
|
|
24
|
-
}
|
|
25
|
-
schema: SchemaSchema
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Creates a coupon condition that requires a specific buyer
|
|
30
|
-
* @param buyer The buyer's address
|
|
31
|
-
* @returns A coupon condition that requires a specific buyer
|
|
32
|
-
*/
|
|
33
|
-
export const createConditionForRequiredBuyer = (buyer: Address): BuyerCondition => {
|
|
34
|
-
return {
|
|
35
|
-
schema: SchemaSchema,
|
|
36
|
-
definition: {
|
|
37
|
-
type: 'array',
|
|
38
|
-
contains: {
|
|
39
|
-
type: 'object',
|
|
40
|
-
properties: {
|
|
41
|
-
schema: { type: 'string', const: 'network.xyo.escrow.terms' },
|
|
42
|
-
buyer: {
|
|
43
|
-
type: 'array', items: { type: 'string', const: buyer }, minItems: 1,
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
required: ['schema', 'buyer'],
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { AsObjectFactory } from '@xylabs/object'
|
|
2
|
-
import type { Payload, WithSources } from '@xyo-network/payload-model'
|
|
3
|
-
import {
|
|
4
|
-
asSchema,
|
|
5
|
-
isPayloadOfSchemaType,
|
|
6
|
-
isPayloadOfSchemaTypeWithSources,
|
|
7
|
-
} from '@xyo-network/payload-model'
|
|
8
|
-
|
|
9
|
-
import type { AmountFields } from '../../../../Amount/index.ts'
|
|
10
|
-
import { CouponSchema } from '../Schema.ts'
|
|
11
|
-
import type { CouponFields } from '../types/index.ts'
|
|
12
|
-
|
|
13
|
-
export const FixedAmountCouponSchema = asSchema(`${CouponSchema}.fixed.amount`, true)
|
|
14
|
-
export type FixedAmountCouponSchema = typeof FixedAmountCouponSchema
|
|
15
|
-
|
|
16
|
-
export interface FixedAmountCouponFields extends CouponFields, AmountFields {}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* A coupon that provides a fixed discount amount
|
|
20
|
-
*/
|
|
21
|
-
export type FixedAmountCoupon = Payload<FixedAmountCouponFields, FixedAmountCouponSchema>
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Identity function for determining if an object is an FixedAmountCoupon
|
|
25
|
-
*/
|
|
26
|
-
export const isFixedAmountCoupon = isPayloadOfSchemaType<FixedAmountCoupon>(FixedAmountCouponSchema)
|
|
27
|
-
export const asFixedAmountCoupon = AsObjectFactory.create<FixedAmountCoupon>(isFixedAmountCoupon)
|
|
28
|
-
export const asOptionalFixedAmountCoupon = AsObjectFactory.createOptional<FixedAmountCoupon>(isFixedAmountCoupon)
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Identity function for determining if an object is an FixedAmountCoupon with sources
|
|
32
|
-
*/
|
|
33
|
-
export const isFixedAmountCouponWithSources = isPayloadOfSchemaTypeWithSources<WithSources<FixedAmountCoupon>>(FixedAmountCouponSchema)
|
|
34
|
-
export const asFixedAmountCouponWithSources = AsObjectFactory.create<WithSources<FixedAmountCoupon>>(isFixedAmountCouponWithSources)
|
|
35
|
-
export const asOptionalFixedAmountCouponWithSources = AsObjectFactory.createOptional<WithSources<FixedAmountCoupon>>(isFixedAmountCouponWithSources)
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { AsObjectFactory } from '@xylabs/object'
|
|
2
|
-
import type { Payload, WithSources } from '@xyo-network/payload-model'
|
|
3
|
-
import {
|
|
4
|
-
asSchema,
|
|
5
|
-
isPayloadOfSchemaType,
|
|
6
|
-
isPayloadOfSchemaTypeWithSources,
|
|
7
|
-
} from '@xyo-network/payload-model'
|
|
8
|
-
|
|
9
|
-
import { CouponSchema } from '../Schema.ts'
|
|
10
|
-
import type { CouponFields } from '../types/index.ts'
|
|
11
|
-
|
|
12
|
-
export const FixedPercentageCouponSchema = asSchema(`${CouponSchema}.fixed.percentage`, true)
|
|
13
|
-
export type FixedPercentageCouponSchema = typeof FixedPercentageCouponSchema
|
|
14
|
-
|
|
15
|
-
export interface FixedPercentageCouponFields extends CouponFields {
|
|
16
|
-
percentage: number
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* A coupon that provides a fixed discount amount
|
|
21
|
-
*/
|
|
22
|
-
export type FixedPercentageCoupon = Payload<FixedPercentageCouponFields, FixedPercentageCouponSchema>
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Identity function for determining if an object is an FixedPercentageCoupon
|
|
26
|
-
*/
|
|
27
|
-
export const isFixedPercentageCoupon = isPayloadOfSchemaType<FixedPercentageCoupon>(FixedPercentageCouponSchema)
|
|
28
|
-
export const asFixedPercentageCoupon = AsObjectFactory.create<FixedPercentageCoupon>(isFixedPercentageCoupon)
|
|
29
|
-
export const asOptionalFixedPercentageCoupon = AsObjectFactory.createOptional<FixedPercentageCoupon>(isFixedPercentageCoupon)
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Identity function for determining if an object is an FixedPercentageCoupon with sources
|
|
33
|
-
*/
|
|
34
|
-
export const isFixedPercentageCouponWithSources = isPayloadOfSchemaTypeWithSources<WithSources<FixedPercentageCoupon>>(FixedPercentageCouponSchema)
|
|
35
|
-
export const asFixedPercentageCouponWithSources = AsObjectFactory.create<WithSources<FixedPercentageCoupon>>(isFixedPercentageCouponWithSources)
|
|
36
|
-
export const asOptionalFixedPercentageCouponWithSources = AsObjectFactory.createOptional<WithSources<FixedPercentageCoupon>>(isFixedPercentageCouponWithSources)
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { AsObjectFactory } from '@xylabs/object'
|
|
2
|
-
import type { Payload, WithSources } from '@xyo-network/payload-model'
|
|
3
|
-
import {
|
|
4
|
-
asSchema,
|
|
5
|
-
isPayloadOfSchemaType,
|
|
6
|
-
isPayloadOfSchemaTypeWithSources,
|
|
7
|
-
} from '@xyo-network/payload-model'
|
|
8
|
-
|
|
9
|
-
import type { AmountFields } from '../../../../Amount/index.ts'
|
|
10
|
-
import { CouponSchema } from '../Schema.ts'
|
|
11
|
-
import type { CouponFields } from '../types/index.ts'
|
|
12
|
-
|
|
13
|
-
export const FixedPriceCouponSchema = asSchema(`${CouponSchema}.fixed.price`, true)
|
|
14
|
-
export type FixedPriceCouponSchema = typeof FixedPriceCouponSchema
|
|
15
|
-
|
|
16
|
-
export interface FixedPriceCouponFields extends CouponFields, AmountFields { }
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* A coupon that provides a fixed total price
|
|
20
|
-
*/
|
|
21
|
-
export type FixedPriceCoupon = Payload<FixedPriceCouponFields, FixedPriceCouponSchema>
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Identity function for determining if an object is an FixedPriceCoupon
|
|
25
|
-
*/
|
|
26
|
-
export const isFixedPriceCoupon = isPayloadOfSchemaType<FixedPriceCoupon>(FixedPriceCouponSchema)
|
|
27
|
-
export const asFixedPriceCoupon = AsObjectFactory.create<FixedPriceCoupon>(isFixedPriceCoupon)
|
|
28
|
-
export const asOptionalFixedPriceCoupon = AsObjectFactory.createOptional<FixedPriceCoupon>(isFixedPriceCoupon)
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Identity function for determining if an object is an FixedPriceCoupon with sources
|
|
32
|
-
*/
|
|
33
|
-
export const isFixedPriceCouponWithSources = isPayloadOfSchemaTypeWithSources<WithSources<FixedPriceCoupon>>(FixedPriceCouponSchema)
|
|
34
|
-
export const asFixedPriceCouponWithSources = AsObjectFactory.create<WithSources<FixedPriceCoupon>>(isFixedPriceCouponWithSources)
|
|
35
|
-
export const asOptionalFixedPriceCouponWithSources = AsObjectFactory.createOptional<WithSources<FixedPriceCoupon>>(isFixedPriceCouponWithSources)
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { AsObjectFactory } from '@xylabs/object'
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
FixedAmountCoupon, FixedPercentageCoupon, FixedPriceCoupon,
|
|
5
|
-
} from './Coupons/index.ts'
|
|
6
|
-
import {
|
|
7
|
-
isFixedAmountCoupon, isFixedAmountCouponWithSources, isFixedPercentageCoupon,
|
|
8
|
-
isFixedPercentageCouponWithSources,
|
|
9
|
-
isFixedPriceCoupon,
|
|
10
|
-
isFixedPriceCouponWithSources,
|
|
11
|
-
} from './Coupons/index.ts'
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* The type of coupons
|
|
15
|
-
*/
|
|
16
|
-
export type Coupon
|
|
17
|
-
= FixedAmountCoupon
|
|
18
|
-
| FixedPercentageCoupon
|
|
19
|
-
| FixedPriceCoupon
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Identity function for determining if an object is an Coupon
|
|
23
|
-
*/
|
|
24
|
-
export const isCoupon = (x?: unknown | null) =>
|
|
25
|
-
isFixedAmountCoupon(x)
|
|
26
|
-
|| isFixedPercentageCoupon(x)
|
|
27
|
-
|| isFixedPriceCoupon(x)
|
|
28
|
-
export const asCoupon = AsObjectFactory.create(isCoupon)
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Identity function for determining if an object is an Coupon with sources
|
|
32
|
-
*/
|
|
33
|
-
export const isCouponWithSources = (x?: unknown | null) =>
|
|
34
|
-
isFixedAmountCouponWithSources(x)
|
|
35
|
-
|| isFixedPercentageCouponWithSources(x)
|
|
36
|
-
|| isFixedPriceCouponWithSources(x)
|
|
37
|
-
export const asCouponWithSources = AsObjectFactory.create(isCouponWithSources)
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { AsObjectFactory } from '@xylabs/object'
|
|
2
|
-
import { isPayloadOfSchemaType, isPayloadOfSchemaTypeWithSources } from '@xyo-network/payload-model'
|
|
3
|
-
import type { SchemaPayload } from '@xyo-network/schema-payload-plugin'
|
|
4
|
-
import { SchemaSchema } from '@xyo-network/schema-payload-plugin'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* The payloads that can be used as conditions for a coupon
|
|
8
|
-
*/
|
|
9
|
-
export type Condition = SchemaPayload
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Identity function for determining if an object is a Condition payload
|
|
13
|
-
*/
|
|
14
|
-
export const isCondition = isPayloadOfSchemaType<Condition>(SchemaSchema)
|
|
15
|
-
export const asCondition = AsObjectFactory.create(isCondition)
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Identity function for determining if an object is a Condition payload with sources
|
|
19
|
-
*/
|
|
20
|
-
export const isConditionWithSources = isPayloadOfSchemaTypeWithSources<Condition>(SchemaSchema)
|
|
21
|
-
export const asConditionWithSources = AsObjectFactory.create(isConditionWithSources)
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { Hash } from '@xylabs/hex'
|
|
2
|
-
import type { DurationFields } from '@xyo-network/xns-record-payload-plugins'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* The fields that are common across all coupons
|
|
6
|
-
*/
|
|
7
|
-
export interface CouponFields extends DurationFields {
|
|
8
|
-
/**
|
|
9
|
-
* The conditions that must be met in order for this coupon to be applied
|
|
10
|
-
*/
|
|
11
|
-
conditions?: Hash[]
|
|
12
|
-
/**
|
|
13
|
-
* Whether or not this discount can be stacked with other discounts
|
|
14
|
-
*/
|
|
15
|
-
stackable?: boolean
|
|
16
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { AsObjectFactory } from '@xylabs/object'
|
|
2
|
-
import type { Payload, WithSources } from '@xyo-network/payload-model'
|
|
3
|
-
import {
|
|
4
|
-
asSchema,
|
|
5
|
-
isPayloadOfSchemaType,
|
|
6
|
-
isPayloadOfSchemaTypeWithSources,
|
|
7
|
-
} from '@xyo-network/payload-model'
|
|
8
|
-
|
|
9
|
-
import type { AmountFields } from '../../Amount/index.ts'
|
|
10
|
-
|
|
11
|
-
export const DiscountSchema = asSchema('network.xyo.payments.discount', true)
|
|
12
|
-
export type DiscountSchema = typeof DiscountSchema
|
|
13
|
-
|
|
14
|
-
export interface DiscountFields extends AmountFields { }
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* The result of a discount
|
|
18
|
-
*/
|
|
19
|
-
export type Discount = Payload<DiscountFields, DiscountSchema>
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Identity function for determining if an object is an Discount
|
|
23
|
-
*/
|
|
24
|
-
export const isDiscount = isPayloadOfSchemaType<Discount>(DiscountSchema)
|
|
25
|
-
export const asDiscount = AsObjectFactory.create<Discount>(isDiscount)
|
|
26
|
-
export const asOptionalDiscount = AsObjectFactory.createOptional<Discount>(isDiscount)
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Identity function for determining if an object is an Discount with sources
|
|
30
|
-
*/
|
|
31
|
-
export const isDiscountWithSources = isPayloadOfSchemaTypeWithSources<Discount>(DiscountSchema)
|
|
32
|
-
export const asDiscountWithSources = AsObjectFactory.create<WithSources<Discount>>(isDiscountWithSources)
|
|
33
|
-
export const asOptionalDiscountWithSources = AsObjectFactory.createOptional<WithSources<Discount>>(isDiscountWithSources)
|
package/src/Discount/index.ts
DELETED
package/src/Escrow/Outcome.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { Hash } from '@xylabs/hex'
|
|
2
|
-
import { AsObjectFactory } from '@xylabs/object'
|
|
3
|
-
import type { PayloadWithSources, WithSources } from '@xyo-network/payload-model'
|
|
4
|
-
import {
|
|
5
|
-
asSchema,
|
|
6
|
-
isPayloadOfSchemaType,
|
|
7
|
-
isPayloadOfSchemaTypeWithSources,
|
|
8
|
-
} from '@xyo-network/payload-model'
|
|
9
|
-
|
|
10
|
-
import { EscrowSchema } from './Schema.ts'
|
|
11
|
-
|
|
12
|
-
export const EscrowOutcomeSchema = asSchema(`${EscrowSchema}.outcome`, true)
|
|
13
|
-
export type EscrowOutcomeSchema = typeof EscrowOutcomeSchema
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* The possible outcomes for an escrow
|
|
17
|
-
*/
|
|
18
|
-
export type EscrowOutcomes = 'fulfilled' | 'expired' // TODO: More outcomes
|
|
19
|
-
|
|
20
|
-
export interface EscrowOutcomeFields {
|
|
21
|
-
outcome: EscrowOutcomes
|
|
22
|
-
terms: Hash
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* The terms of an escrow
|
|
27
|
-
*/
|
|
28
|
-
export type EscrowOutcome = PayloadWithSources<EscrowOutcomeFields, EscrowOutcomeSchema>
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Identity function for determining if an object is an EscrowOutcome
|
|
32
|
-
*/
|
|
33
|
-
export const isEscrowOutcome = isPayloadOfSchemaType<EscrowOutcome>(EscrowOutcomeSchema)
|
|
34
|
-
export const asEscrowOutcome = AsObjectFactory.create<EscrowOutcome>(isEscrowOutcome)
|
|
35
|
-
export const asOptionalEscrowOutcome = AsObjectFactory.createOptional<EscrowOutcome>(isEscrowOutcome)
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Identity function for determining if an object is an EscrowOutcome with sources
|
|
39
|
-
*/
|
|
40
|
-
export const isEscrowOutcomeWithSources = isPayloadOfSchemaTypeWithSources<EscrowOutcome>(EscrowOutcomeSchema)
|
|
41
|
-
export const asEscrowOutcomeWithSources = AsObjectFactory.createOptional<WithSources<EscrowOutcome>>(isEscrowOutcomeWithSources)
|
|
42
|
-
export const asOptionalEscrowOutcomeWithSources = AsObjectFactory.createOptional<WithSources<EscrowOutcome>>(isEscrowOutcomeWithSources)
|
package/src/Escrow/Schema.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import type { Address, Hash } from '@xylabs/hex'
|
|
2
|
-
import { AsObjectFactory } from '@xylabs/object'
|
|
3
|
-
import type { Payload } from '@xyo-network/payload-model'
|
|
4
|
-
import {
|
|
5
|
-
asSchema, isPayloadOfSchemaType, isPayloadOfSchemaTypeWithSources,
|
|
6
|
-
} from '@xyo-network/payload-model'
|
|
7
|
-
|
|
8
|
-
import { EscrowSchema } from '../Schema.ts'
|
|
9
|
-
|
|
10
|
-
export const EscrowTermsSchema = asSchema(`${EscrowSchema}.terms`, true)
|
|
11
|
-
export type EscrowTermsSchema = typeof EscrowTermsSchema
|
|
12
|
-
|
|
13
|
-
// TODO: Include escrow agent in escrow terms
|
|
14
|
-
export interface EscrowTermsFields {
|
|
15
|
-
/**
|
|
16
|
-
* The trusted estimators for the worth of the things being sold
|
|
17
|
-
*/
|
|
18
|
-
appraisalAuthorities: Address[]
|
|
19
|
-
/**
|
|
20
|
-
* The estimated worths of the things being sold
|
|
21
|
-
*/
|
|
22
|
-
appraisals: Hash[]
|
|
23
|
-
/**
|
|
24
|
-
* The things being sold
|
|
25
|
-
*/
|
|
26
|
-
assets: Hash[]
|
|
27
|
-
/**
|
|
28
|
-
* The buyer
|
|
29
|
-
*/
|
|
30
|
-
buyer: Address[]
|
|
31
|
-
/**
|
|
32
|
-
* The buyer
|
|
33
|
-
*/
|
|
34
|
-
buyerSecret: Hash
|
|
35
|
-
/**
|
|
36
|
-
* Any discounts (coupons, vouchers, credits, etc.) to be applied to the escrow
|
|
37
|
-
*/
|
|
38
|
-
discounts: Hash[]
|
|
39
|
-
/**
|
|
40
|
-
* The escrow agent responsible for the escrow
|
|
41
|
-
*/
|
|
42
|
-
escrowAgent: Address
|
|
43
|
-
/**
|
|
44
|
-
* The time the escrow expires
|
|
45
|
-
*/
|
|
46
|
-
exp: number
|
|
47
|
-
/**
|
|
48
|
-
* The time the escrow starts
|
|
49
|
-
*/
|
|
50
|
-
nbf: number
|
|
51
|
-
/**
|
|
52
|
-
* The trusted payment authorities
|
|
53
|
-
*/
|
|
54
|
-
paymentAuthorities: Address[]
|
|
55
|
-
/**
|
|
56
|
-
* The seller
|
|
57
|
-
*/
|
|
58
|
-
seller: Address[]
|
|
59
|
-
/**
|
|
60
|
-
* The seller
|
|
61
|
-
*/
|
|
62
|
-
sellerSecret: Hash
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* The terms of an escrow
|
|
67
|
-
*/
|
|
68
|
-
export type EscrowTerms = Payload<Partial<EscrowTermsFields>, EscrowTermsSchema>
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Identity function for determining if an object is an EscrowTerms
|
|
72
|
-
*/
|
|
73
|
-
export const isEscrowTerms = isPayloadOfSchemaType<EscrowTerms>(EscrowTermsSchema)
|
|
74
|
-
export const asEscrowTerms = AsObjectFactory.create<EscrowTerms>(isEscrowTerms)
|
|
75
|
-
export const asOptionalEscrowTerms = AsObjectFactory.createOptional<EscrowTerms>(isEscrowTerms)
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Identity function for determining if an object is an EscrowTerms with sources
|
|
79
|
-
*/
|
|
80
|
-
export const isEscrowTermsWithSources = isPayloadOfSchemaTypeWithSources<EscrowTerms>(EscrowTermsSchema)
|
|
81
|
-
export const asEscrowTermsWithSources = AsObjectFactory.create<EscrowTerms>(isEscrowTermsWithSources)
|
|
82
|
-
export const asOptionalEscrowTermsWithSources = AsObjectFactory.createOptional<EscrowTerms>(isEscrowTermsWithSources)
|
package/src/Escrow/index.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { Hash } from '@xylabs/hex'
|
|
2
|
-
import type { HashLeaseEstimate } from '@xyo-network/diviner-hash-lease'
|
|
3
|
-
import { isHashLeaseEstimateWithSources } from '@xyo-network/diviner-hash-lease'
|
|
4
|
-
import type { Payload, WithSources } from '@xyo-network/payload-model'
|
|
5
|
-
|
|
6
|
-
import type { EscrowTerms } from '../../Terms/index.ts'
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Returns a dictionary of asset hashes and their associated appraisals
|
|
10
|
-
* @param terms The escrow terms
|
|
11
|
-
* @param dictionary The dictionary of payloads associated with the escrow terms
|
|
12
|
-
* @returns A dictionary of asset hashes and their associated appraisals
|
|
13
|
-
*/
|
|
14
|
-
export const getAppraisalsByAsset = (terms: EscrowTerms, dictionary: Record<Hash, Payload>): Record<Hash, WithSources<HashLeaseEstimate>[]> => {
|
|
15
|
-
const assets = terms.assets
|
|
16
|
-
if (!assets || assets.length === 0) return {}
|
|
17
|
-
const appraisals = Object.values(dictionary).filter(isHashLeaseEstimateWithSources) as unknown as WithSources<HashLeaseEstimate>[]
|
|
18
|
-
const appraisalsByAsset: Record<Hash, WithSources<HashLeaseEstimate>[]> = {}
|
|
19
|
-
for (const estimate of appraisals) {
|
|
20
|
-
const { $sources } = estimate
|
|
21
|
-
if ($sources === undefined || $sources.length === 0) {
|
|
22
|
-
continue
|
|
23
|
-
}
|
|
24
|
-
for (const asset of assets) {
|
|
25
|
-
if ($sources.includes(asset)) {
|
|
26
|
-
if (!appraisalsByAsset[asset]) appraisalsByAsset[asset] = []
|
|
27
|
-
appraisalsByAsset[asset].push(estimate)
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return appraisalsByAsset
|
|
32
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { Hash } from '@xylabs/hex'
|
|
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 { EscrowTerms } from '../../Terms/index.ts'
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Returns a dictionary of appraisals and their associated bound witnesses which are signed by
|
|
10
|
-
* valid appraisal authorities from the escrow terms
|
|
11
|
-
* @param terms The escrow terms
|
|
12
|
-
* @param dictionary The diction of payloads associated with the escrow terms
|
|
13
|
-
* @returns A dictionary of appraisals and their associated bound witnesses
|
|
14
|
-
*/
|
|
15
|
-
export const getSignaturesByAppraisal = (
|
|
16
|
-
terms: EscrowTerms,
|
|
17
|
-
dictionary: Record<Hash, Payload>,
|
|
18
|
-
): Record<Hash, BoundWitness[]> => {
|
|
19
|
-
// Validate inputs
|
|
20
|
-
const appraisals = terms.appraisals
|
|
21
|
-
if (!appraisals || appraisals.length === 0) return {}
|
|
22
|
-
const appraisalAuthorities = terms.appraisalAuthorities
|
|
23
|
-
if (!appraisalAuthorities || appraisalAuthorities.length === 0) return {}
|
|
24
|
-
|
|
25
|
-
// Validate the appraisals are signed by valid appraisal authorities. Validation criteria:
|
|
26
|
-
// - The bw includes the appraisal hash from the escrow terms appraisal
|
|
27
|
-
// - The bw is signed by an approved appraisal authority from the escrow terms appraisalAuthorities
|
|
28
|
-
const appraisalBWsValid: Record<Hash, BoundWitness[]> = Object.fromEntries(
|
|
29
|
-
appraisals.map<[Hash, BoundWitness[]]>(hash => [hash, []]),
|
|
30
|
-
)
|
|
31
|
-
for (const bw of Object.values(dictionary).filter(isBoundWitness)) {
|
|
32
|
-
for (const appraisal of appraisals) {
|
|
33
|
-
if (bw.payload_hashes.includes(appraisal) && bw.addresses.some(address => appraisalAuthorities.includes(address))) {
|
|
34
|
-
appraisalBWsValid[appraisal].push(bw)
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return appraisalBWsValid
|
|
40
|
-
}
|
package/src/Escrow/util/index.ts
DELETED
|
@@ -1,17 +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
|
-
|
|
5
|
-
import type { EscrowTerms } from '../../Terms/index.ts'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Creates an escrow intent (for a buyer or seller) using the supplied secret
|
|
9
|
-
* @param terms The payload describing the terms for the escrow
|
|
10
|
-
* @param secret The secret for the escrow principal party to use for the escrow
|
|
11
|
-
* @param account The account to create the escrow intent with
|
|
12
|
-
* @returns The escrow intent
|
|
13
|
-
*/
|
|
14
|
-
export const createEscrowIntentWithSecret = async (terms: EscrowTerms, secret: Id, account: AccountInstance) => {
|
|
15
|
-
const result = await new BoundWitnessBuilder().signers([account]).payloads([terms, secret]).build()
|
|
16
|
-
return result
|
|
17
|
-
}
|