@xyo-network/payment-payload-plugins 3.1.2 → 3.2.0-rc.2
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 +0 -4
- package/dist/neutral/Amount/Payload.d.ts.map +1 -1
- package/dist/neutral/Billing/Address/Address.d.ts +46 -10
- package/dist/neutral/Billing/Address/Address.d.ts.map +1 -1
- package/dist/neutral/Discount/Payload/Coupon/Coupons/FixedAmount.d.ts +44 -8
- package/dist/neutral/Discount/Payload/Coupon/Coupons/FixedAmount.d.ts.map +1 -1
- package/dist/neutral/Discount/Payload/Coupon/Coupons/FixedPercentage.d.ts +40 -8
- package/dist/neutral/Discount/Payload/Coupon/Coupons/FixedPercentage.d.ts.map +1 -1
- package/dist/neutral/Discount/Payload/Coupon/Coupons/FixedPrice.d.ts +44 -8
- package/dist/neutral/Discount/Payload/Coupon/Coupons/FixedPrice.d.ts.map +1 -1
- package/dist/neutral/Discount/Payload/Coupon/Payload.d.ts +101 -5
- package/dist/neutral/Discount/Payload/Coupon/Payload.d.ts.map +1 -1
- package/dist/neutral/Discount/Payload/Coupon/types/Condition.d.ts +68 -9
- package/dist/neutral/Discount/Payload/Coupon/types/Condition.d.ts.map +1 -1
- package/dist/neutral/Discount/Payload/Discount.d.ts +7 -7
- package/dist/neutral/Discount/Payload/Discount.d.ts.map +1 -1
- package/dist/neutral/Escrow/Outcome.d.ts +0 -4
- package/dist/neutral/Escrow/Outcome.d.ts.map +1 -1
- package/dist/neutral/Escrow/Terms/Terms.d.ts +28 -10
- package/dist/neutral/Escrow/Terms/Terms.d.ts.map +1 -1
- package/dist/neutral/Escrow/util/appraisal/getAppraisalsByAsset.d.ts +2 -2
- package/dist/neutral/Escrow/util/appraisal/getAppraisalsByAsset.d.ts.map +1 -1
- package/dist/neutral/Escrow/util/appraisal/getSignaturesByAppraisal.d.ts +2 -2
- package/dist/neutral/Escrow/util/appraisal/getSignaturesByAppraisal.d.ts.map +1 -1
- package/dist/neutral/Escrow/util/secret/createEscrowIntent.d.ts +32 -11
- package/dist/neutral/Escrow/util/secret/createEscrowIntent.d.ts.map +1 -1
- package/dist/neutral/Escrow/util/secret/findEscrowPartySecretSignatures.d.ts +3 -3
- package/dist/neutral/Escrow/util/secret/findEscrowPartySecretSignatures.d.ts.map +1 -1
- package/dist/neutral/Escrow/util/secret/updateEscrowTermsWithSecret.d.ts +32 -11
- package/dist/neutral/Escrow/util/secret/updateEscrowTermsWithSecret.d.ts.map +1 -1
- package/dist/neutral/Escrow/validators/common/SecretValidators/getPartySecretSignedValidator.d.ts +2 -2
- package/dist/neutral/Escrow/validators/common/SecretValidators/getPartySecretSignedValidator.d.ts.map +1 -1
- package/dist/neutral/Escrow/validators/escrow/appraisal.d.ts +4 -4
- package/dist/neutral/Escrow/validators/escrow/appraisal.d.ts.map +1 -1
- package/dist/neutral/Escrow/validators/escrow/buyerSecret.d.ts +3 -3
- package/dist/neutral/Escrow/validators/escrow/buyerSecret.d.ts.map +1 -1
- package/dist/neutral/Escrow/validators/escrow/sellerSecret.d.ts +3 -3
- package/dist/neutral/Escrow/validators/escrow/sellerSecret.d.ts.map +1 -1
- package/dist/neutral/Payment/Instrument/Card/Payload.d.ts +22 -10
- package/dist/neutral/Payment/Instrument/Card/Payload.d.ts.map +1 -1
- package/dist/neutral/Payment/Payload.d.ts +0 -4
- package/dist/neutral/Payment/Payload.d.ts.map +1 -1
- package/dist/neutral/Payment/Status/Payload.d.ts +0 -4
- package/dist/neutral/Payment/Status/Payload.d.ts.map +1 -1
- package/dist/neutral/Purchase/Payload.d.ts +0 -4
- package/dist/neutral/Purchase/Payload.d.ts.map +1 -1
- package/dist/neutral/Receipt/Payload.d.ts +0 -4
- package/dist/neutral/Receipt/Payload.d.ts.map +1 -1
- package/dist/neutral/Subtotal/Diviner/Payload.d.ts +0 -4
- package/dist/neutral/Subtotal/Diviner/Payload.d.ts.map +1 -1
- package/dist/neutral/Total/Diviner/Payload.d.ts +0 -4
- package/dist/neutral/Total/Diviner/Payload.d.ts.map +1 -1
- package/dist/neutral/index.mjs +39 -76
- package/dist/neutral/index.mjs.map +1 -1
- package/package.json +25 -23
- package/src/Amount/Payload.ts +0 -6
- package/src/Billing/Address/Address.ts +1 -8
- package/src/Discount/Payload/Coupon/Coupons/FixedAmount.ts +6 -9
- package/src/Discount/Payload/Coupon/Coupons/FixedPercentage.ts +6 -9
- package/src/Discount/Payload/Coupon/Coupons/FixedPrice.ts +6 -9
- package/src/Discount/Payload/Coupon/Payload.ts +5 -11
- package/src/Discount/Payload/Coupon/types/Condition.ts +6 -10
- package/src/Discount/Payload/Discount.ts +2 -8
- package/src/Escrow/Outcome.ts +0 -6
- package/src/Escrow/Terms/Terms.ts +1 -8
- package/src/Escrow/util/appraisal/getAppraisalsByAsset.ts +5 -7
- package/src/Escrow/util/appraisal/getSignaturesByAppraisal.ts +7 -7
- package/src/Escrow/util/secret/createEscrowIntent.ts +1 -1
- package/src/Escrow/util/secret/findEscrowPartySecretSignatures.ts +4 -5
- package/src/Escrow/validators/common/SecretValidators/getPartySecretSignedValidator.ts +2 -4
- package/src/Escrow/validators/escrow/appraisal.ts +8 -9
- package/src/Escrow/validators/escrow/buyerSecret.ts +3 -3
- package/src/Escrow/validators/escrow/sellerSecret.ts +3 -3
- package/src/Payment/Instrument/Card/Payload.ts +1 -8
- package/src/Payment/Payload.ts +0 -6
- package/src/Payment/Status/Payload.ts +0 -6
- package/src/Purchase/Payload.ts +0 -6
- package/src/Receipt/Payload.ts +0 -6
- package/src/Subtotal/Diviner/Payload.ts +0 -6
- package/src/Total/Diviner/Payload.ts +0 -6
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { AsObjectFactory } from '@xylabs/object'
|
|
2
|
+
import type { Payload, PayloadWithOptionalSources } from '@xyo-network/payload-model'
|
|
2
3
|
import {
|
|
3
4
|
isPayloadOfSchemaType,
|
|
4
|
-
isPayloadOfSchemaTypeWithMeta,
|
|
5
5
|
isPayloadOfSchemaTypeWithSources,
|
|
6
6
|
} from '@xyo-network/payload-model'
|
|
7
7
|
|
|
@@ -18,19 +18,16 @@ export interface FixedPercentageCouponFields extends CouponFields {
|
|
|
18
18
|
/**
|
|
19
19
|
* A coupon that provides a fixed discount amount
|
|
20
20
|
*/
|
|
21
|
-
export type FixedPercentageCoupon =
|
|
21
|
+
export type FixedPercentageCoupon = PayloadWithOptionalSources<Payload<FixedPercentageCouponFields, FixedPercentageCouponSchema>>
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* Identity function for determining if an object is an FixedPercentageCoupon
|
|
25
25
|
*/
|
|
26
26
|
export const isFixedPercentageCoupon = isPayloadOfSchemaType<FixedPercentageCoupon>(FixedPercentageCouponSchema)
|
|
27
|
+
export const asFixedPercentageCoupon = AsObjectFactory.create(isFixedPercentageCoupon)
|
|
27
28
|
|
|
28
29
|
/**
|
|
29
30
|
* Identity function for determining if an object is an FixedPercentageCoupon with sources
|
|
30
|
-
|
|
31
|
+
*/
|
|
31
32
|
export const isFixedPercentageCouponWithSources = isPayloadOfSchemaTypeWithSources<FixedPercentageCoupon>(FixedPercentageCouponSchema)
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Identity function for determining if an object is an FixedPercentageCoupon with meta
|
|
35
|
-
*/
|
|
36
|
-
export const isFixedPercentageCouponWithMeta = isPayloadOfSchemaTypeWithMeta<FixedPercentageCoupon>(FixedPercentageCouponSchema)
|
|
33
|
+
export const asFixedPercentageCouponWithSources = AsObjectFactory.create(isFixedPercentageCouponWithSources)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { AsObjectFactory } from '@xylabs/object'
|
|
2
|
+
import type { PayloadWithOptionalSources } from '@xyo-network/payload-model'
|
|
2
3
|
import {
|
|
3
4
|
isPayloadOfSchemaType,
|
|
4
|
-
isPayloadOfSchemaTypeWithMeta,
|
|
5
5
|
isPayloadOfSchemaTypeWithSources,
|
|
6
6
|
} from '@xyo-network/payload-model'
|
|
7
7
|
|
|
@@ -17,19 +17,16 @@ export interface FixedPriceCouponFields extends CouponFields, AmountFields { }
|
|
|
17
17
|
/**
|
|
18
18
|
* A coupon that provides a fixed total price
|
|
19
19
|
*/
|
|
20
|
-
export type FixedPriceCoupon =
|
|
20
|
+
export type FixedPriceCoupon = PayloadWithOptionalSources<FixedPriceCouponFields, FixedPriceCouponSchema>
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* Identity function for determining if an object is an FixedPriceCoupon
|
|
24
24
|
*/
|
|
25
25
|
export const isFixedPriceCoupon = isPayloadOfSchemaType<FixedPriceCoupon>(FixedPriceCouponSchema)
|
|
26
|
+
export const asFixedPriceCoupon = AsObjectFactory.create(isFixedPriceCoupon)
|
|
26
27
|
|
|
27
28
|
/**
|
|
28
29
|
* Identity function for determining if an object is an FixedPriceCoupon with sources
|
|
29
|
-
|
|
30
|
+
*/
|
|
30
31
|
export const isFixedPriceCouponWithSources = isPayloadOfSchemaTypeWithSources<FixedPriceCoupon>(FixedPriceCouponSchema)
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Identity function for determining if an object is an FixedPriceCoupon with meta
|
|
34
|
-
*/
|
|
35
|
-
export const isFixedPriceCouponWithMeta = isPayloadOfSchemaTypeWithMeta<FixedPriceCoupon>(FixedPriceCouponSchema)
|
|
32
|
+
export const asFixedPriceCouponWithSources = AsObjectFactory.create(isFixedPriceCouponWithSources)
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { AsObjectFactory } from '@xylabs/object'
|
|
2
|
+
|
|
1
3
|
import {
|
|
2
4
|
type FixedAmountCoupon, type FixedPercentageCoupon, type FixedPriceCoupon,
|
|
3
|
-
isFixedAmountCoupon,
|
|
4
|
-
isFixedPercentageCouponWithMeta,
|
|
5
|
+
isFixedAmountCoupon, isFixedAmountCouponWithSources, isFixedPercentageCoupon,
|
|
5
6
|
isFixedPercentageCouponWithSources,
|
|
6
7
|
isFixedPriceCoupon,
|
|
7
|
-
isFixedPriceCouponWithMeta,
|
|
8
8
|
isFixedPriceCouponWithSources,
|
|
9
9
|
} from './Coupons/index.ts'
|
|
10
10
|
|
|
@@ -23,6 +23,7 @@ export const isCoupon = (x?: unknown | null) =>
|
|
|
23
23
|
isFixedAmountCoupon(x)
|
|
24
24
|
|| isFixedPercentageCoupon(x)
|
|
25
25
|
|| isFixedPriceCoupon(x)
|
|
26
|
+
export const asCoupon = AsObjectFactory.create(isCoupon)
|
|
26
27
|
|
|
27
28
|
/**
|
|
28
29
|
* Identity function for determining if an object is an Coupon with sources
|
|
@@ -31,11 +32,4 @@ export const isCouponWithSources = (x?: unknown | null) =>
|
|
|
31
32
|
isFixedAmountCouponWithSources(x)
|
|
32
33
|
|| isFixedPercentageCouponWithSources(x)
|
|
33
34
|
|| isFixedPriceCouponWithSources(x)
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Identity function for determining if an object is an Coupon with meta
|
|
37
|
-
*/
|
|
38
|
-
export const isCouponWithMeta = (x?: unknown | null) =>
|
|
39
|
-
isFixedAmountCouponWithMeta(x)
|
|
40
|
-
|| isFixedPercentageCouponWithMeta(x)
|
|
41
|
-
|| isFixedPriceCouponWithMeta(x)
|
|
35
|
+
export const asCouponWithSources = AsObjectFactory.create(isCouponWithSources)
|
|
@@ -1,24 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from '@xyo-network/payload-model'
|
|
1
|
+
import { AsObjectFactory } from '@xylabs/object'
|
|
2
|
+
import { isPayloadOfSchemaType, isPayloadOfSchemaTypeWithSources } from '@xyo-network/payload-model'
|
|
4
3
|
import { type SchemaPayload, SchemaSchema } from '@xyo-network/schema-payload-plugin'
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* The payloads that can be used as conditions for a coupon
|
|
8
7
|
*/
|
|
9
|
-
export type Condition = SchemaPayload
|
|
8
|
+
export type Condition = SchemaPayload
|
|
10
9
|
|
|
11
10
|
/**
|
|
12
11
|
* Identity function for determining if an object is a Condition payload
|
|
13
12
|
*/
|
|
14
13
|
export const isCondition = isPayloadOfSchemaType<Condition>(SchemaSchema)
|
|
14
|
+
export const asCondition = AsObjectFactory.create(isCondition)
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Identity function for determining if an object is a Condition payload with sources
|
|
18
|
-
|
|
18
|
+
*/
|
|
19
19
|
export const isConditionWithSources = isPayloadOfSchemaTypeWithSources<Condition>(SchemaSchema)
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Identity function for determining if an object is a Condition payload with meta
|
|
23
|
-
*/
|
|
24
|
-
export const isConditionWithMeta = isPayloadOfSchemaTypeWithMeta<Condition>(SchemaSchema)
|
|
20
|
+
export const asConditionWithSources = AsObjectFactory.create(isConditionWithSources)
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PayloadWithOptionalSources } from '@xyo-network/payload-model'
|
|
2
2
|
import {
|
|
3
3
|
isPayloadOfSchemaType,
|
|
4
|
-
isPayloadOfSchemaTypeWithMeta,
|
|
5
4
|
isPayloadOfSchemaTypeWithSources,
|
|
6
5
|
} from '@xyo-network/payload-model'
|
|
7
6
|
|
|
@@ -15,7 +14,7 @@ export interface DiscountFields extends AmountFields { }
|
|
|
15
14
|
/**
|
|
16
15
|
* The result of a discount
|
|
17
16
|
*/
|
|
18
|
-
export type Discount =
|
|
17
|
+
export type Discount = PayloadWithOptionalSources<DiscountFields, DiscountSchema>
|
|
19
18
|
|
|
20
19
|
/**
|
|
21
20
|
* Identity function for determining if an object is an Discount
|
|
@@ -26,8 +25,3 @@ export const isDiscount = isPayloadOfSchemaType<Discount>(DiscountSchema)
|
|
|
26
25
|
* Identity function for determining if an object is an Discount with sources
|
|
27
26
|
*/
|
|
28
27
|
export const isDiscountWithSources = isPayloadOfSchemaTypeWithSources<Discount>(DiscountSchema)
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Identity function for determining if an object is an Discount with meta
|
|
32
|
-
*/
|
|
33
|
-
export const isDiscountWithMeta = isPayloadOfSchemaTypeWithMeta<Discount>(DiscountSchema)
|
package/src/Escrow/Outcome.ts
CHANGED
|
@@ -2,7 +2,6 @@ import type { Hash } from '@xylabs/hex'
|
|
|
2
2
|
import type { PayloadWithSources } from '@xyo-network/payload-model'
|
|
3
3
|
import {
|
|
4
4
|
isPayloadOfSchemaType,
|
|
5
|
-
isPayloadOfSchemaTypeWithMeta,
|
|
6
5
|
isPayloadOfSchemaTypeWithSources,
|
|
7
6
|
} from '@xyo-network/payload-model'
|
|
8
7
|
|
|
@@ -35,8 +34,3 @@ export const isEscrowOutcome = isPayloadOfSchemaType<EscrowOutcome>(EscrowOutcom
|
|
|
35
34
|
* Identity function for determining if an object is an EscrowOutcome with sources
|
|
36
35
|
*/
|
|
37
36
|
export const isEscrowOutcomeWithSources = isPayloadOfSchemaTypeWithSources<EscrowOutcome>(EscrowOutcomeSchema)
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Identity function for determining if an object is an EscrowOutcome with meta
|
|
41
|
-
*/
|
|
42
|
-
export const isEscrowOutcomeWithMeta = isPayloadOfSchemaTypeWithMeta<EscrowOutcome>(EscrowOutcomeSchema)
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { Address, Hash } from '@xylabs/hex'
|
|
2
2
|
import type { Payload } from '@xyo-network/payload-model'
|
|
3
|
-
import {
|
|
4
|
-
isPayloadOfSchemaType, isPayloadOfSchemaTypeWithMeta, isPayloadOfSchemaTypeWithSources,
|
|
5
|
-
} from '@xyo-network/payload-model'
|
|
3
|
+
import { isPayloadOfSchemaType, isPayloadOfSchemaTypeWithSources } from '@xyo-network/payload-model'
|
|
6
4
|
|
|
7
5
|
import { EscrowSchema } from '../Schema.ts'
|
|
8
6
|
|
|
@@ -75,8 +73,3 @@ export const isEscrowTerms = isPayloadOfSchemaType<EscrowTerms>(EscrowTermsSchem
|
|
|
75
73
|
* Identity function for determining if an object is an EscrowTerms with sources
|
|
76
74
|
*/
|
|
77
75
|
export const isEscrowTermsWithSources = isPayloadOfSchemaTypeWithSources<EscrowTerms>(EscrowTermsSchema)
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Identity function for determining if an object is an EscrowTerms with meta
|
|
81
|
-
*/
|
|
82
|
-
export const isEscrowTermsWithMeta = isPayloadOfSchemaTypeWithMeta<EscrowTerms>(EscrowTermsSchema)
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { Hash } from '@xylabs/hex'
|
|
2
2
|
import { type HashLeaseEstimate, isHashLeaseEstimateWithSources } from '@xyo-network/diviner-hash-lease'
|
|
3
|
-
import type {
|
|
4
|
-
Payload, WithMeta, WithSources,
|
|
5
|
-
} from '@xyo-network/payload-model'
|
|
3
|
+
import type { Payload, WithSources } from '@xyo-network/payload-model'
|
|
6
4
|
|
|
7
5
|
import type { EscrowTerms } from '../../Terms/index.ts'
|
|
8
6
|
|
|
@@ -12,18 +10,18 @@ import type { EscrowTerms } from '../../Terms/index.ts'
|
|
|
12
10
|
* @param dictionary The dictionary of payloads associated with the escrow terms
|
|
13
11
|
* @returns A dictionary of asset hashes and their associated appraisals
|
|
14
12
|
*/
|
|
15
|
-
export const getAppraisalsByAsset = (terms: EscrowTerms, dictionary: Record<Hash,
|
|
13
|
+
export const getAppraisalsByAsset = (terms: EscrowTerms, dictionary: Record<Hash, Payload>): Record<Hash, WithSources<HashLeaseEstimate>[]> => {
|
|
16
14
|
const assets = terms.assets
|
|
17
15
|
if (!assets || assets.length === 0) return {}
|
|
18
16
|
const appraisals = Object.values(dictionary).filter(isHashLeaseEstimateWithSources) as unknown as WithSources<HashLeaseEstimate>[]
|
|
19
17
|
const appraisalsByAsset: Record<Hash, WithSources<HashLeaseEstimate>[]> = {}
|
|
20
18
|
for (const estimate of appraisals) {
|
|
21
|
-
const { sources } = estimate
|
|
22
|
-
if (sources === undefined || sources.length === 0) {
|
|
19
|
+
const { $sources } = estimate
|
|
20
|
+
if ($sources === undefined || $sources.length === 0) {
|
|
23
21
|
continue
|
|
24
22
|
}
|
|
25
23
|
for (const asset of assets) {
|
|
26
|
-
if (sources.includes(asset)) {
|
|
24
|
+
if ($sources.includes(asset)) {
|
|
27
25
|
if (!appraisalsByAsset[asset]) appraisalsByAsset[asset] = []
|
|
28
26
|
appraisalsByAsset[asset].push(estimate)
|
|
29
27
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Hash } from '@xylabs/hex'
|
|
2
|
-
import { type BoundWitness,
|
|
3
|
-
import type { Payload
|
|
2
|
+
import { type BoundWitness, isBoundWitness } from '@xyo-network/boundwitness-model'
|
|
3
|
+
import type { Payload } from '@xyo-network/payload-model'
|
|
4
4
|
|
|
5
5
|
import type { EscrowTerms } from '../../Terms/index.ts'
|
|
6
6
|
|
|
@@ -13,8 +13,8 @@ import type { EscrowTerms } from '../../Terms/index.ts'
|
|
|
13
13
|
*/
|
|
14
14
|
export const getSignaturesByAppraisal = (
|
|
15
15
|
terms: EscrowTerms,
|
|
16
|
-
dictionary: Record<Hash,
|
|
17
|
-
): Record<Hash,
|
|
16
|
+
dictionary: Record<Hash, Payload>,
|
|
17
|
+
): Record<Hash, BoundWitness[]> => {
|
|
18
18
|
// Validate inputs
|
|
19
19
|
const appraisals = terms.appraisals
|
|
20
20
|
if (!appraisals || appraisals.length === 0) return {}
|
|
@@ -24,10 +24,10 @@ export const getSignaturesByAppraisal = (
|
|
|
24
24
|
// Validate the appraisals are signed by valid appraisal authorities. Validation criteria:
|
|
25
25
|
// - The bw includes the appraisal hash from the escrow terms appraisal
|
|
26
26
|
// - The bw is signed by an approved appraisal authority from the escrow terms appraisalAuthorities
|
|
27
|
-
const appraisalBWsValid: Record<Hash,
|
|
28
|
-
appraisals.map<[Hash,
|
|
27
|
+
const appraisalBWsValid: Record<Hash, BoundWitness[]> = Object.fromEntries(
|
|
28
|
+
appraisals.map<[Hash, BoundWitness[]]>(hash => [hash, []]),
|
|
29
29
|
)
|
|
30
|
-
for (const bw of Object.values(dictionary).filter(
|
|
30
|
+
for (const bw of Object.values(dictionary).filter(isBoundWitness)) {
|
|
31
31
|
for (const appraisal of appraisals) {
|
|
32
32
|
if (bw.payload_hashes.includes(appraisal) && bw.addresses.some(address => appraisalAuthorities.includes(address))) {
|
|
33
33
|
appraisalBWsValid[appraisal].push(bw)
|
|
@@ -12,6 +12,6 @@ import type { EscrowTerms } from '../../Terms/index.ts'
|
|
|
12
12
|
* @returns The escrow intent
|
|
13
13
|
*/
|
|
14
14
|
export const createEscrowIntentWithSecret = async (terms: EscrowTerms, secret: IdPayload, account: AccountInstance) => {
|
|
15
|
-
const result = await new BoundWitnessBuilder(
|
|
15
|
+
const result = await new BoundWitnessBuilder().signers([account]).payloads([terms, secret]).build()
|
|
16
16
|
return result
|
|
17
17
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { Hash } from '@xylabs/hex'
|
|
2
|
-
import type
|
|
3
|
-
import {
|
|
4
|
-
import type { Payload, WithMeta } from '@xyo-network/payload-model'
|
|
2
|
+
import { type BoundWitness, isBoundWitness } from '@xyo-network/boundwitness-model'
|
|
3
|
+
import type { Payload } from '@xyo-network/payload-model'
|
|
5
4
|
|
|
6
5
|
import type {
|
|
7
6
|
EscrowParty, EscrowPartySecret, EscrowTerms,
|
|
@@ -23,7 +22,7 @@ const getLogPrefix = (party: EscrowParty) => {
|
|
|
23
22
|
* @param party The party to get the secret signatures for
|
|
24
23
|
* @returns An array of BoundWitnesses containing the secret signed by all the parties
|
|
25
24
|
*/
|
|
26
|
-
export const findEscrowPartySecretSignatures = (terms: EscrowTerms, dictionary: Record<Hash,
|
|
25
|
+
export const findEscrowPartySecretSignatures = (terms: EscrowTerms, dictionary: Record<Hash, Payload>, party: EscrowParty): BoundWitness[] => {
|
|
27
26
|
const partyAddresses = terms[party]
|
|
28
27
|
if (partyAddresses === undefined || partyAddresses.length === 0) {
|
|
29
28
|
console.log(`${getLogPrefix(party)}: No ${party}: ${terms[party]}`)
|
|
@@ -38,7 +37,7 @@ export const findEscrowPartySecretSignatures = (terms: EscrowTerms, dictionary:
|
|
|
38
37
|
// BWs containing the secret signed by all the parties
|
|
39
38
|
const partySignedBWs = Object.values(dictionary)
|
|
40
39
|
// Find all BoundWitnesses
|
|
41
|
-
.filter(
|
|
40
|
+
.filter(isBoundWitness)
|
|
42
41
|
// That contain the seller secret
|
|
43
42
|
.filter(bw => bw.payload_hashes.includes(secretHash))
|
|
44
43
|
// That are signed by all the parties
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { Hash } from '@xylabs/hex'
|
|
2
2
|
import { BoundWitnessValidator } from '@xyo-network/boundwitness-validator'
|
|
3
|
-
import type {
|
|
4
|
-
AsyncPayloadValidationFunction, Payload, WithMeta,
|
|
5
|
-
} from '@xyo-network/payload-model'
|
|
3
|
+
import type { AsyncPayloadValidationFunction, Payload } from '@xyo-network/payload-model'
|
|
6
4
|
|
|
7
5
|
import type {
|
|
8
6
|
EscrowParty, EscrowPartySecret, EscrowTerms,
|
|
@@ -24,7 +22,7 @@ const getLogPrefix = (party: EscrowParty) => {
|
|
|
24
22
|
* @param dictionary Payload dictionary of the escrow terms
|
|
25
23
|
* @returns A function that validates the escrow terms for the existence of the party secret signed by the party
|
|
26
24
|
*/
|
|
27
|
-
export const getPartySecretSignedValidator = (dictionary: Record<Hash,
|
|
25
|
+
export const getPartySecretSignedValidator = (dictionary: Record<Hash, Payload>, party: EscrowParty): AsyncPayloadValidationFunction<EscrowTerms> => {
|
|
28
26
|
const partySecret: EscrowPartySecret = party === 'seller' ? 'sellerSecret' : 'buyerSecret'
|
|
29
27
|
return async (terms: EscrowTerms): Promise<boolean> => {
|
|
30
28
|
// Party-signed party secret BWs
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/assert'
|
|
2
2
|
import type { Hash } from '@xylabs/hex'
|
|
3
|
-
import type
|
|
4
|
-
import { isBoundWitnessWithMeta } from '@xyo-network/boundwitness-model'
|
|
3
|
+
import { type BoundWitness, isBoundWitness } from '@xyo-network/boundwitness-model'
|
|
5
4
|
import type { HashLeaseEstimate } from '@xyo-network/diviner-hash-lease'
|
|
6
5
|
import type {
|
|
7
|
-
Payload, SyncPayloadValidationFunction,
|
|
6
|
+
Payload, SyncPayloadValidationFunction, WithSources,
|
|
8
7
|
} from '@xyo-network/payload-model'
|
|
9
8
|
|
|
10
9
|
import type { EscrowTerms } from '../../Terms/index.ts'
|
|
@@ -32,7 +31,7 @@ export const appraisalsExistValidator: SyncPayloadValidationFunction<EscrowTerms
|
|
|
32
31
|
* @param dictionary Payload dictionary of the escrow terms
|
|
33
32
|
* @returns A function that validates the escrow terms for appraisals which are from valid authorities
|
|
34
33
|
*/
|
|
35
|
-
export const getAppraisalsFromValidAuthoritiesValidator = (dictionary: Record<Hash,
|
|
34
|
+
export const getAppraisalsFromValidAuthoritiesValidator = (dictionary: Record<Hash, Payload>): SyncPayloadValidationFunction<EscrowTerms> => {
|
|
36
35
|
return (terms: EscrowTerms) => {
|
|
37
36
|
const appraisals = assertEx(terms.appraisals, () => `${name}: No appraisals: ${terms.appraisals}`)
|
|
38
37
|
const appraisalAuthorities = assertEx(terms.appraisalAuthorities, () => `${name}: No appraisalAuthorities: ${terms.appraisalAuthorities}`)
|
|
@@ -40,10 +39,10 @@ export const getAppraisalsFromValidAuthoritiesValidator = (dictionary: Record<Ha
|
|
|
40
39
|
// Validate the appraisals are signed by valid appraisal authorities. Validation criteria:
|
|
41
40
|
// - We have a bw for each of the appraisal
|
|
42
41
|
// - The bw is signed by an approved appraisal authority
|
|
43
|
-
const appraisalBWsValid: Record<Hash,
|
|
44
|
-
appraisals.map<[Hash,
|
|
42
|
+
const appraisalBWsValid: Record<Hash, BoundWitness[]> = Object.fromEntries(
|
|
43
|
+
appraisals.map<[Hash, BoundWitness[]]>(hash => [hash, []]),
|
|
45
44
|
)
|
|
46
|
-
for (const bw of Object.values(dictionary).filter(
|
|
45
|
+
for (const bw of Object.values(dictionary).filter(isBoundWitness)) {
|
|
47
46
|
for (const appraisal of appraisals) {
|
|
48
47
|
if (bw.payload_hashes.includes(appraisal) && bw.addresses.some(address => appraisalAuthorities.includes(address))) {
|
|
49
48
|
appraisalBWsValid[appraisal].push(bw)
|
|
@@ -68,7 +67,7 @@ export const getAppraisalsFromValidAuthoritiesValidator = (dictionary: Record<Ha
|
|
|
68
67
|
* @returns A function that validates the escrow terms for appraisals which are valid
|
|
69
68
|
*/
|
|
70
69
|
export const getAppraisalsValidValidator = (
|
|
71
|
-
dictionary: Record<Hash,
|
|
70
|
+
dictionary: Record<Hash, Payload>,
|
|
72
71
|
minimumExp: number,
|
|
73
72
|
): SyncPayloadValidationFunction<EscrowTerms> => {
|
|
74
73
|
return (terms: EscrowTerms) => {
|
|
@@ -94,7 +93,7 @@ export const getAppraisalsValidValidator = (
|
|
|
94
93
|
* @param dictionary Payload dictionary of the escrow terms
|
|
95
94
|
* @returns A function that validates the escrow terms for appraisals
|
|
96
95
|
*/
|
|
97
|
-
export const getAppraisalsForAllAssetsValidator = (dictionary: Record<Hash,
|
|
96
|
+
export const getAppraisalsForAllAssetsValidator = (dictionary: Record<Hash, Payload>): SyncPayloadValidationFunction<EscrowTerms> => {
|
|
98
97
|
return (terms: EscrowTerms) => {
|
|
99
98
|
// Verify we have an estimate for each of the assets
|
|
100
99
|
const assets = assertEx(terms.assets, () => `${name}: No assets: ${terms.assets}`)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/assert'
|
|
2
2
|
import type { Hash } from '@xylabs/hex'
|
|
3
3
|
import type {
|
|
4
|
-
AsyncPayloadValidationFunction, Payload, SyncPayloadValidationFunction,
|
|
4
|
+
AsyncPayloadValidationFunction, Payload, SyncPayloadValidationFunction,
|
|
5
5
|
} from '@xyo-network/payload-model'
|
|
6
6
|
|
|
7
7
|
import type { EscrowTerms } from '../../Terms/index.ts'
|
|
@@ -28,7 +28,7 @@ export const buyerSecretExistsValidator: SyncPayloadValidationFunction<EscrowTer
|
|
|
28
28
|
* @param dictionary Payload dictionary of the escrow terms
|
|
29
29
|
* @returns A function that validates the escrow terms for the existence of the buyerSecret in the dictionary
|
|
30
30
|
*/
|
|
31
|
-
export const getBuyerSecretSuppliedValidator = (dictionary: Record<Hash,
|
|
31
|
+
export const getBuyerSecretSuppliedValidator = (dictionary: Record<Hash, Payload>): SyncPayloadValidationFunction<EscrowTerms> => {
|
|
32
32
|
return (terms: EscrowTerms) => {
|
|
33
33
|
const buyerSecret = assertEx(terms.buyerSecret, () => `${name}: No buyerSecret: ${terms.buyerSecret}`)
|
|
34
34
|
if (!dictionary[buyerSecret]) {
|
|
@@ -44,6 +44,6 @@ export const getBuyerSecretSuppliedValidator = (dictionary: Record<Hash, WithMet
|
|
|
44
44
|
* @param dictionary Payload dictionary of the escrow terms
|
|
45
45
|
* @returns A function that validates the escrow terms for the existence of the buyerSecret signed by the buyer
|
|
46
46
|
*/
|
|
47
|
-
export const getBuyerSecretSignedValidator = (dictionary: Record<Hash,
|
|
47
|
+
export const getBuyerSecretSignedValidator = (dictionary: Record<Hash, Payload>): AsyncPayloadValidationFunction<EscrowTerms> => {
|
|
48
48
|
return getPartySecretSignedValidator(dictionary, 'buyer')
|
|
49
49
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/assert'
|
|
2
2
|
import type { Hash } from '@xylabs/hex'
|
|
3
3
|
import type {
|
|
4
|
-
AsyncPayloadValidationFunction, Payload, SyncPayloadValidationFunction,
|
|
4
|
+
AsyncPayloadValidationFunction, Payload, SyncPayloadValidationFunction,
|
|
5
5
|
} from '@xyo-network/payload-model'
|
|
6
6
|
|
|
7
7
|
import type { EscrowTerms } from '../../Terms/index.ts'
|
|
@@ -28,7 +28,7 @@ export const sellerSecretExistsValidator: SyncPayloadValidationFunction<EscrowTe
|
|
|
28
28
|
* @param dictionary Payload dictionary of the escrow terms
|
|
29
29
|
* @returns A function that validates the escrow terms for the existence of the sellerSecret in the dictionary
|
|
30
30
|
*/
|
|
31
|
-
export const getSellerSecretSuppliedValidator = (dictionary: Record<Hash,
|
|
31
|
+
export const getSellerSecretSuppliedValidator = (dictionary: Record<Hash, Payload>): SyncPayloadValidationFunction<EscrowTerms> => {
|
|
32
32
|
return (terms: EscrowTerms) => {
|
|
33
33
|
const sellerSecret = assertEx(terms.sellerSecret, () => `${name}: No sellerSecret: ${terms.sellerSecret}`)
|
|
34
34
|
if (!dictionary[sellerSecret]) {
|
|
@@ -44,6 +44,6 @@ export const getSellerSecretSuppliedValidator = (dictionary: Record<Hash, WithMe
|
|
|
44
44
|
* @param dictionary Payload dictionary of the escrow terms
|
|
45
45
|
* @returns A function that validates the escrow terms for the existence of the sellerSecret signed by the seller
|
|
46
46
|
*/
|
|
47
|
-
export const getSellerSecretSignedValidator = (dictionary: Record<Hash,
|
|
47
|
+
export const getSellerSecretSignedValidator = (dictionary: Record<Hash, Payload>): AsyncPayloadValidationFunction<EscrowTerms> => {
|
|
48
48
|
return getPartySecretSignedValidator(dictionary, 'seller')
|
|
49
49
|
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type { Payload } from '@xyo-network/payload-model'
|
|
2
|
-
import {
|
|
3
|
-
isPayloadOfSchemaType, isPayloadOfSchemaTypeWithMeta, isPayloadOfSchemaTypeWithSources,
|
|
4
|
-
} from '@xyo-network/payload-model'
|
|
2
|
+
import { isPayloadOfSchemaType, isPayloadOfSchemaTypeWithSources } from '@xyo-network/payload-model'
|
|
5
3
|
|
|
6
4
|
import { PaymentCardSchema } from './Schema.ts'
|
|
7
5
|
|
|
@@ -45,8 +43,3 @@ export const isPaymentCard = isPayloadOfSchemaType<PaymentCard>(PaymentCardSchem
|
|
|
45
43
|
* Identity function for determine if an object is a PaymentCard with sources
|
|
46
44
|
*/
|
|
47
45
|
export const isPaymentCardWithSources = isPayloadOfSchemaTypeWithSources<PaymentCard>(PaymentCardSchema)
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Identity function for determine if an object is a PaymentCard with meta
|
|
51
|
-
*/
|
|
52
|
-
export const isPaymentCardWithMeta = isPayloadOfSchemaTypeWithMeta<PaymentCard>(PaymentCardSchema)
|
package/src/Payment/Payload.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { PayloadWithSources } from '@xyo-network/payload-model'
|
|
2
2
|
import {
|
|
3
3
|
isPayloadOfSchemaType,
|
|
4
|
-
isPayloadOfSchemaTypeWithMeta,
|
|
5
4
|
isPayloadOfSchemaTypeWithSources,
|
|
6
5
|
} from '@xyo-network/payload-model'
|
|
7
6
|
|
|
@@ -33,8 +32,3 @@ export const isPayment = isPayloadOfSchemaType<Payment>(PaymentSchema)
|
|
|
33
32
|
* Identity function for determine if an object is a Payment with sources
|
|
34
33
|
*/
|
|
35
34
|
export const isPaymentWithSources = isPayloadOfSchemaTypeWithSources<Payment>(PaymentSchema)
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Identity function for determine if an object is a Payment with meta
|
|
39
|
-
*/
|
|
40
|
-
export const isPaymentWithMeta = isPayloadOfSchemaTypeWithMeta<Payment>(PaymentSchema)
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { PayloadWithSources } from '@xyo-network/payload-model'
|
|
2
2
|
import {
|
|
3
3
|
isPayloadOfSchemaType,
|
|
4
|
-
isPayloadOfSchemaTypeWithMeta,
|
|
5
4
|
isPayloadOfSchemaTypeWithSources,
|
|
6
5
|
} from '@xyo-network/payload-model'
|
|
7
6
|
|
|
@@ -33,8 +32,3 @@ export const isPaymentStatus = isPayloadOfSchemaType<PaymentStatus>(PaymentStatu
|
|
|
33
32
|
* Identity function for determine if an object is a PaymentStatus with sources
|
|
34
33
|
*/
|
|
35
34
|
export const isPaymentStatusWithSources = isPayloadOfSchemaTypeWithSources<PaymentStatus>(PaymentStatusSchema)
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Identity function for determine if an object is a PaymentStatus with meta
|
|
39
|
-
*/
|
|
40
|
-
export const isPaymentStatusWithMeta = isPayloadOfSchemaTypeWithMeta<PaymentStatus>(PaymentStatusSchema)
|
package/src/Purchase/Payload.ts
CHANGED
|
@@ -2,7 +2,6 @@ import type { Hash } from '@xylabs/hex'
|
|
|
2
2
|
import type { PayloadWithSources } from '@xyo-network/payload-model'
|
|
3
3
|
import {
|
|
4
4
|
isPayloadOfSchemaType,
|
|
5
|
-
isPayloadOfSchemaTypeWithMeta,
|
|
6
5
|
isPayloadOfSchemaTypeWithSources,
|
|
7
6
|
} from '@xyo-network/payload-model'
|
|
8
7
|
|
|
@@ -34,8 +33,3 @@ export const isPurchase = isPayloadOfSchemaType<Purchase>(PurchaseSchema)
|
|
|
34
33
|
* Identity function for determine if an object is a Purchase with sources
|
|
35
34
|
*/
|
|
36
35
|
export const isPurchaseWithSources = isPayloadOfSchemaTypeWithSources<Purchase>(PurchaseSchema)
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Identity function for determine if an object is a Purchase with meta
|
|
40
|
-
*/
|
|
41
|
-
export const isPurchaseWithMeta = isPayloadOfSchemaTypeWithMeta<Purchase>(PurchaseSchema)
|
package/src/Receipt/Payload.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { PayloadWithSources } from '@xyo-network/payload-model'
|
|
2
2
|
import {
|
|
3
3
|
isPayloadOfSchemaType,
|
|
4
|
-
isPayloadOfSchemaTypeWithMeta,
|
|
5
4
|
isPayloadOfSchemaTypeWithSources,
|
|
6
5
|
} from '@xyo-network/payload-model'
|
|
7
6
|
|
|
@@ -33,8 +32,3 @@ export const isReceipt = isPayloadOfSchemaType<Receipt>(ReceiptSchema)
|
|
|
33
32
|
* Identity function for determine if an object is a Receipt with sources
|
|
34
33
|
*/
|
|
35
34
|
export const isReceiptWithSources = isPayloadOfSchemaTypeWithSources<Receipt>(ReceiptSchema)
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Identity function for determine if an object is a Receipt with meta
|
|
39
|
-
*/
|
|
40
|
-
export const isReceiptWithMeta = isPayloadOfSchemaTypeWithMeta<Receipt>(ReceiptSchema)
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { PayloadWithSources } from '@xyo-network/payload-model'
|
|
2
2
|
import {
|
|
3
3
|
isPayloadOfSchemaType,
|
|
4
|
-
isPayloadOfSchemaTypeWithMeta,
|
|
5
4
|
isPayloadOfSchemaTypeWithSources,
|
|
6
5
|
} from '@xyo-network/payload-model'
|
|
7
6
|
|
|
@@ -26,8 +25,3 @@ export const isSubtotal = isPayloadOfSchemaType<Subtotal>(SubtotalSchema)
|
|
|
26
25
|
* Identity function for determining if an object is an Subtotal with sources
|
|
27
26
|
*/
|
|
28
27
|
export const isSubtotalWithSources = isPayloadOfSchemaTypeWithSources<Subtotal>(SubtotalSchema)
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Identity function for determining if an object is an Subtotal with meta
|
|
32
|
-
*/
|
|
33
|
-
export const isSubtotalWithMeta = isPayloadOfSchemaTypeWithMeta<Subtotal>(SubtotalSchema)
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { PayloadWithSources } from '@xyo-network/payload-model'
|
|
2
2
|
import {
|
|
3
3
|
isPayloadOfSchemaType,
|
|
4
|
-
isPayloadOfSchemaTypeWithMeta,
|
|
5
4
|
isPayloadOfSchemaTypeWithSources,
|
|
6
5
|
} from '@xyo-network/payload-model'
|
|
7
6
|
|
|
@@ -26,8 +25,3 @@ export const isTotal = isPayloadOfSchemaType<Total>(TotalSchema)
|
|
|
26
25
|
* Identity function for determining if an object is an Total with sources
|
|
27
26
|
*/
|
|
28
27
|
export const isTotalWithSources = isPayloadOfSchemaTypeWithSources<Total>(TotalSchema)
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Identity function for determining if an object is an Total with meta
|
|
32
|
-
*/
|
|
33
|
-
export const isTotalWithMeta = isPayloadOfSchemaTypeWithMeta<Total>(TotalSchema)
|