@xyo-network/payment-payload-plugins 3.0.22 → 3.0.24

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.
Files changed (78) hide show
  1. package/dist/neutral/Escrow/Terms/Party.d.ts +3 -0
  2. package/dist/neutral/Escrow/Terms/Party.d.ts.map +1 -0
  3. package/dist/neutral/Escrow/Terms/PartySecret.d.ts +3 -0
  4. package/dist/neutral/Escrow/Terms/PartySecret.d.ts.map +1 -0
  5. package/dist/neutral/Escrow/Terms/Terms.d.ts.map +1 -0
  6. package/dist/neutral/Escrow/Terms/index.d.ts +4 -0
  7. package/dist/neutral/Escrow/Terms/index.d.ts.map +1 -0
  8. package/dist/neutral/Escrow/index.d.ts +2 -3
  9. package/dist/neutral/Escrow/index.d.ts.map +1 -1
  10. package/dist/neutral/Escrow/util/index.d.ts +2 -0
  11. package/dist/neutral/Escrow/util/index.d.ts.map +1 -0
  12. package/dist/neutral/Escrow/{createEscrowIntent.d.ts → util/secret/createEscrowIntent.d.ts} +1 -1
  13. package/dist/neutral/Escrow/util/secret/createEscrowIntent.d.ts.map +1 -0
  14. package/dist/neutral/Escrow/util/secret/findEscrowPartySecretSignatures.d.ts +6 -0
  15. package/dist/neutral/Escrow/util/secret/findEscrowPartySecretSignatures.d.ts.map +1 -0
  16. package/dist/neutral/Escrow/util/secret/getEscrowSecret.d.ts.map +1 -0
  17. package/dist/neutral/Escrow/util/secret/index.d.ts +4 -0
  18. package/dist/neutral/Escrow/util/secret/index.d.ts.map +1 -0
  19. package/dist/neutral/Escrow/validators/common/ModuleInstanceValidators/moduleInstanceValidators.d.ts +1 -1
  20. package/dist/neutral/Escrow/validators/common/ModuleInstanceValidators/moduleInstanceValidators.d.ts.map +1 -1
  21. package/dist/neutral/Escrow/validators/common/SecretValidators/getPartySecretSignedValidator.d.ts +5 -0
  22. package/dist/neutral/Escrow/validators/common/SecretValidators/getPartySecretSignedValidator.d.ts.map +1 -0
  23. package/dist/neutral/Escrow/validators/common/SecretValidators/index.d.ts +2 -0
  24. package/dist/neutral/Escrow/validators/common/SecretValidators/index.d.ts.map +1 -0
  25. package/dist/neutral/Escrow/validators/common/index.d.ts +1 -0
  26. package/dist/neutral/Escrow/validators/common/index.d.ts.map +1 -1
  27. package/dist/neutral/Escrow/validators/escrow/agent.d.ts +3 -3
  28. package/dist/neutral/Escrow/validators/escrow/agent.d.ts.map +1 -1
  29. package/dist/neutral/Escrow/validators/escrow/appraisal.d.ts +6 -6
  30. package/dist/neutral/Escrow/validators/escrow/appraisal.d.ts.map +1 -1
  31. package/dist/neutral/Escrow/validators/escrow/appraisalAuthorities.d.ts +4 -4
  32. package/dist/neutral/Escrow/validators/escrow/appraisalAuthorities.d.ts.map +1 -1
  33. package/dist/neutral/Escrow/validators/escrow/assets.d.ts +3 -3
  34. package/dist/neutral/Escrow/validators/escrow/assets.d.ts.map +1 -1
  35. package/dist/neutral/Escrow/validators/escrow/buyer.d.ts +3 -3
  36. package/dist/neutral/Escrow/validators/escrow/buyer.d.ts.map +1 -1
  37. package/dist/neutral/Escrow/validators/escrow/buyerSecret.d.ts +5 -5
  38. package/dist/neutral/Escrow/validators/escrow/buyerSecret.d.ts.map +1 -1
  39. package/dist/neutral/Escrow/validators/escrow/nbfExp.d.ts +3 -3
  40. package/dist/neutral/Escrow/validators/escrow/nbfExp.d.ts.map +1 -1
  41. package/dist/neutral/Escrow/validators/escrow/paymentAuthorities.d.ts +3 -3
  42. package/dist/neutral/Escrow/validators/escrow/paymentAuthorities.d.ts.map +1 -1
  43. package/dist/neutral/Escrow/validators/escrow/seller.d.ts +3 -3
  44. package/dist/neutral/Escrow/validators/escrow/seller.d.ts.map +1 -1
  45. package/dist/neutral/Escrow/validators/escrow/sellerSecret.d.ts +5 -5
  46. package/dist/neutral/Escrow/validators/escrow/sellerSecret.d.ts.map +1 -1
  47. package/dist/neutral/index.mjs +71 -57
  48. package/dist/neutral/index.mjs.map +1 -1
  49. package/package.json +4 -2
  50. package/src/Escrow/Terms/Party.ts +6 -0
  51. package/src/Escrow/Terms/PartySecret.ts +6 -0
  52. package/src/Escrow/{Terms.ts → Terms/Terms.ts} +1 -1
  53. package/src/Escrow/Terms/index.ts +3 -0
  54. package/src/Escrow/index.ts +2 -3
  55. package/src/Escrow/util/index.ts +1 -0
  56. package/src/Escrow/{createEscrowIntent.ts → util/secret/createEscrowIntent.ts} +1 -1
  57. package/src/Escrow/util/secret/findEscrowPartySecretSignatures.ts +47 -0
  58. package/src/Escrow/util/secret/index.ts +3 -0
  59. package/src/Escrow/validators/common/ModuleInstanceValidators/moduleInstanceValidators.ts +1 -1
  60. package/src/Escrow/validators/common/SecretValidators/getPartySecretSignedValidator.ts +48 -0
  61. package/src/Escrow/validators/common/SecretValidators/index.ts +1 -0
  62. package/src/Escrow/validators/common/index.ts +1 -0
  63. package/src/Escrow/validators/escrow/agent.ts +3 -3
  64. package/src/Escrow/validators/escrow/appraisal.ts +6 -6
  65. package/src/Escrow/validators/escrow/appraisalAuthorities.ts +4 -4
  66. package/src/Escrow/validators/escrow/assets.ts +3 -3
  67. package/src/Escrow/validators/escrow/buyer.ts +3 -3
  68. package/src/Escrow/validators/escrow/buyerSecret.ts +7 -34
  69. package/src/Escrow/validators/escrow/nbfExp.ts +3 -3
  70. package/src/Escrow/validators/escrow/paymentAuthorities.ts +3 -3
  71. package/src/Escrow/validators/escrow/seller.ts +3 -3
  72. package/src/Escrow/validators/escrow/sellerSecret.ts +7 -34
  73. package/dist/neutral/Escrow/Terms.d.ts.map +0 -1
  74. package/dist/neutral/Escrow/createEscrowIntent.d.ts.map +0 -1
  75. package/dist/neutral/Escrow/getEscrowSecret.d.ts.map +0 -1
  76. /package/dist/neutral/Escrow/{Terms.d.ts → Terms/Terms.d.ts} +0 -0
  77. /package/dist/neutral/Escrow/{getEscrowSecret.d.ts → util/secret/getEscrowSecret.d.ts} +0 -0
  78. /package/src/Escrow/{getEscrowSecret.ts → util/secret/getEscrowSecret.ts} +0 -0
@@ -0,0 +1,48 @@
1
+ import type { Hash } from '@xylabs/hex'
2
+ import { BoundWitnessValidator } from '@xyo-network/boundwitness-validator'
3
+ import type {
4
+ AsyncPayloadValidationFunction, Payload, WithMeta,
5
+ } from '@xyo-network/payload-model'
6
+
7
+ import type {
8
+ EscrowParty, EscrowPartySecret, EscrowTerms,
9
+ } from '../../../Terms/index.ts'
10
+ import { findEscrowPartySecretSignatures } from '../../../util/index.ts'
11
+
12
+ /**
13
+ * Returns the log prefix for the party
14
+ * @param party The party
15
+ * @returns The log prefix for the party
16
+ */
17
+ const getLogPrefix = (party: EscrowParty) => {
18
+ const partySecret: EscrowPartySecret = party === 'seller' ? 'sellerSecret' : 'buyerSecret'
19
+ return `EscrowTerms.${partySecret}`
20
+ }
21
+
22
+ /**
23
+ * Returns a function that validates the escrow terms for the existence of the party secret signed by the party
24
+ * @param dictionary Payload dictionary of the escrow terms
25
+ * @returns A function that validates the escrow terms for the existence of the party secret signed by the party
26
+ */
27
+ export const getPartySecretSignedValidator = (dictionary: Record<Hash, WithMeta<Payload>>, party: EscrowParty): AsyncPayloadValidationFunction<EscrowTerms> => {
28
+ const partySecret: EscrowPartySecret = party === 'seller' ? 'sellerSecret' : 'buyerSecret'
29
+ return async (terms: EscrowTerms): Promise<boolean> => {
30
+ // Party-signed party secret BWs
31
+ const buyerSecretBWs = findEscrowPartySecretSignatures(terms, dictionary, party)
32
+
33
+ // If there are no BWs, return false
34
+ if (buyerSecretBWs.length === 0) {
35
+ console.log(`${getLogPrefix(party)}: No BoundWitnesses supplied for ${partySecret}: ${terms[partySecret]}`)
36
+ return false
37
+ }
38
+
39
+ // Ensure each BW supplied for the party secret is valid
40
+ const errors = await Promise.all(buyerSecretBWs.map(bw => new BoundWitnessValidator(bw).validate()))
41
+ const validBoundWitnesses = errors.every(errors => errors.length === 0)
42
+ if (!validBoundWitnesses) {
43
+ console.log(`${getLogPrefix(party)}: Invalid BoundWitnesses supplied for ${partySecret}: ${terms[partySecret]}`)
44
+ return false
45
+ }
46
+ return true
47
+ }
48
+ }
@@ -0,0 +1 @@
1
+ export * from './getPartySecretSignedValidator.ts'
@@ -1,2 +1,3 @@
1
1
  export * from './ModuleInstanceValidators/index.ts'
2
+ export * from './SecretValidators/index.ts'
2
3
  export * from './TemporalValidators/index.ts'
@@ -1,12 +1,12 @@
1
1
  import type { ModuleIdentifier } from '@xyo-network/module-model'
2
- import type { PayloadValidationFunction } from '@xyo-network/payload-model'
2
+ import type { SyncPayloadValidationFunction } from '@xyo-network/payload-model'
3
3
 
4
- import type { EscrowTerms } from '../../Terms.ts'
4
+ import type { EscrowTerms } from '../../Terms/index.ts'
5
5
  import { moduleIdentifiersContainsOneOf } from '../common/index.ts'
6
6
 
7
7
  const name = 'EscrowTerms.escrowAgent'
8
8
 
9
- export const getEscrowAgentAllowedValidator = (allowedEscrowAgent: ModuleIdentifier): PayloadValidationFunction<EscrowTerms> => {
9
+ export const getEscrowAgentAllowedValidator = (allowedEscrowAgent: ModuleIdentifier): SyncPayloadValidationFunction<EscrowTerms> => {
10
10
  return (terms: EscrowTerms) => {
11
11
  const result = moduleIdentifiersContainsOneOf(terms, t => t.escrowAgent, [allowedEscrowAgent], true)
12
12
  if (!result) {
@@ -5,10 +5,10 @@ import { isBoundWitnessWithMeta } from '@xyo-network/boundwitness-model'
5
5
  import type { HashLeaseEstimate } from '@xyo-network/diviner-hash-lease'
6
6
  import { isHashLeaseEstimateWithSources } from '@xyo-network/diviner-hash-lease'
7
7
  import type {
8
- Payload, PayloadValidationFunction, WithMeta, WithSources,
8
+ Payload, SyncPayloadValidationFunction, WithMeta, WithSources,
9
9
  } from '@xyo-network/payload-model'
10
10
 
11
- import type { EscrowTerms } from '../../Terms.ts'
11
+ import type { EscrowTerms } from '../../Terms/index.ts'
12
12
  import { validateWithinWindow } from '../common/index.ts'
13
13
 
14
14
  const name = 'EscrowTerms.appraisal'
@@ -17,7 +17,7 @@ const name = 'EscrowTerms.appraisal'
17
17
  * A function that validates the escrow terms for tbe existence of appraisals
18
18
  * @returns True if the escrow terms contain appraisals, false otherwise
19
19
  */
20
- export const appraisalsExistValidator: PayloadValidationFunction<EscrowTerms> = (terms: EscrowTerms) => {
20
+ export const appraisalsExistValidator: SyncPayloadValidationFunction<EscrowTerms> = (terms: EscrowTerms) => {
21
21
  // Validate we have appraisals
22
22
  const appraisals = terms.appraisals
23
23
  if (!appraisals || appraisals.length === 0) {
@@ -32,7 +32,7 @@ export const appraisalsExistValidator: PayloadValidationFunction<EscrowTerms> =
32
32
  * @param dictionary Payload dictionary of the escrow terms
33
33
  * @returns A function that validates the escrow terms for appraisals which are from valid authorities
34
34
  */
35
- export const getAppraisalsFromValidAuthoritiesValidator = (dictionary: Record<Hash, WithMeta<Payload>>): PayloadValidationFunction<EscrowTerms> => {
35
+ export const getAppraisalsFromValidAuthoritiesValidator = (dictionary: Record<Hash, WithMeta<Payload>>): SyncPayloadValidationFunction<EscrowTerms> => {
36
36
  return (terms: EscrowTerms) => {
37
37
  const appraisals = assertEx(terms.appraisals, () => `${name}: No appraisals: ${terms.appraisals}`)
38
38
  const appraisalAuthorities = assertEx(terms.appraisalAuthorities, () => `${name}: No appraisalAuthorities: ${terms.appraisalAuthorities}`)
@@ -70,7 +70,7 @@ export const getAppraisalsFromValidAuthoritiesValidator = (dictionary: Record<Ha
70
70
  export const getAppraisalsValidValidator = (
71
71
  dictionary: Record<Hash, WithMeta<Payload>>,
72
72
  minimumExp: number,
73
- ): PayloadValidationFunction<EscrowTerms> => {
73
+ ): SyncPayloadValidationFunction<EscrowTerms> => {
74
74
  return (terms: EscrowTerms) => {
75
75
  // Verify we have an estimate for each of the assets
76
76
  const estimatesByAsset = getEstimatesByAsset(terms, dictionary)
@@ -94,7 +94,7 @@ export const getAppraisalsValidValidator = (
94
94
  * @param dictionary Payload dictionary of the escrow terms
95
95
  * @returns A function that validates the escrow terms for appraisals
96
96
  */
97
- export const getAppraisalsForAllAssetsValidator = (dictionary: Record<Hash, WithMeta<Payload>>): PayloadValidationFunction<EscrowTerms> => {
97
+ export const getAppraisalsForAllAssetsValidator = (dictionary: Record<Hash, WithMeta<Payload>>): SyncPayloadValidationFunction<EscrowTerms> => {
98
98
  return (terms: EscrowTerms) => {
99
99
  // Verify we have an estimate for each of the assets
100
100
  const estimatesByAsset = getEstimatesByAsset(terms, dictionary)
@@ -1,8 +1,8 @@
1
1
  import { asAddress } from '@xylabs/hex'
2
2
  import type { ModuleIdentifier } from '@xyo-network/module-model'
3
- import type { PayloadValidationFunction } from '@xyo-network/payload-model'
3
+ import type { SyncPayloadValidationFunction } from '@xyo-network/payload-model'
4
4
 
5
- import type { EscrowTerms } from '../../Terms.ts'
5
+ import type { EscrowTerms } from '../../Terms/index.ts'
6
6
  import { moduleIdentifiersContainsAllOf } from '../common/index.ts'
7
7
 
8
8
  const name = 'EscrowTerms.appraisalAuthorities'
@@ -11,7 +11,7 @@ const name = 'EscrowTerms.appraisalAuthorities'
11
11
  * A function that validates the escrow terms for appraisalAuthorities
12
12
  * @returns True if the escrow terms contain appraisalAuthorities, false otherwise
13
13
  */
14
- export const appraisalAuthoritiesExistValidator: PayloadValidationFunction<EscrowTerms> = (terms: EscrowTerms) => {
14
+ export const appraisalAuthoritiesExistValidator: SyncPayloadValidationFunction<EscrowTerms> = (terms: EscrowTerms) => {
15
15
  // Validate we have appraisalAuthorities
16
16
  const appraisalAuthorities = terms.appraisalAuthorities
17
17
  if (!appraisalAuthorities || appraisalAuthorities.length === 0) {
@@ -26,7 +26,7 @@ export const appraisalAuthoritiesExistValidator: PayloadValidationFunction<Escro
26
26
  return true
27
27
  }
28
28
 
29
- export const getAppraisalAuthoritiesAllowedValidator = (allowed: ModuleIdentifier[]): PayloadValidationFunction<EscrowTerms> => {
29
+ export const getAppraisalAuthoritiesAllowedValidator = (allowed: ModuleIdentifier[]): SyncPayloadValidationFunction<EscrowTerms> => {
30
30
  return (terms: EscrowTerms) => {
31
31
  const result = moduleIdentifiersContainsAllOf(terms, t => t.appraisalAuthorities, allowed, true)
32
32
  if (!result) {
@@ -1,6 +1,6 @@
1
- import type { PayloadValidationFunction } from '@xyo-network/payload-model'
1
+ import type { SyncPayloadValidationFunction } from '@xyo-network/payload-model'
2
2
 
3
- import type { EscrowTerms } from '../../Terms.ts'
3
+ import type { EscrowTerms } from '../../Terms/index.ts'
4
4
 
5
5
  const name = 'EscrowTerms.assets'
6
6
 
@@ -8,7 +8,7 @@ const name = 'EscrowTerms.assets'
8
8
  * Returns a function that validates the escrow terms for assets
9
9
  * @returns A function that validates the escrow terms for assets
10
10
  */
11
- export const assetsExistValidator: PayloadValidationFunction<EscrowTerms> = (terms: EscrowTerms) => {
11
+ export const assetsExistValidator: SyncPayloadValidationFunction<EscrowTerms> = (terms: EscrowTerms) => {
12
12
  // Validate we have assets
13
13
  const assets = terms.assets
14
14
  if (!assets || assets.length === 0) {
@@ -1,7 +1,7 @@
1
1
  import { asAddress } from '@xylabs/hex'
2
- import type { PayloadValidationFunction } from '@xyo-network/payload-model'
2
+ import type { SyncPayloadValidationFunction } from '@xyo-network/payload-model'
3
3
 
4
- import type { EscrowTerms } from '../../Terms.ts'
4
+ import type { EscrowTerms } from '../../Terms/index.ts'
5
5
 
6
6
  const name = 'EscrowTerms.buyer'
7
7
 
@@ -9,7 +9,7 @@ const name = 'EscrowTerms.buyer'
9
9
  * A function that validates the escrow terms for buyer
10
10
  * @returns True if the escrow terms contain buyer, false otherwise
11
11
  */
12
- export const buyerExistsValidator: PayloadValidationFunction<EscrowTerms> = (terms: EscrowTerms) => {
12
+ export const buyerExistsValidator: SyncPayloadValidationFunction<EscrowTerms> = (terms: EscrowTerms) => {
13
13
  // Validate we have buyer
14
14
  const buyer = terms.buyer
15
15
  if (!buyer || buyer.length === 0) {
@@ -1,12 +1,11 @@
1
1
  import { assertEx } from '@xylabs/assert'
2
2
  import type { Hash } from '@xylabs/hex'
3
- import { isBoundWitnessWithMeta } from '@xyo-network/boundwitness-model'
4
- import { BoundWitnessValidator } from '@xyo-network/boundwitness-validator'
5
3
  import type {
6
- Payload, PayloadValidationFunction, WithMeta,
4
+ AsyncPayloadValidationFunction, Payload, SyncPayloadValidationFunction, WithMeta,
7
5
  } from '@xyo-network/payload-model'
8
6
 
9
- import type { EscrowTerms } from '../../Terms.ts'
7
+ import type { EscrowTerms } from '../../Terms/index.ts'
8
+ import { getPartySecretSignedValidator } from '../common/index.ts'
10
9
 
11
10
  const name = 'EscrowTerms.buyerSecret'
12
11
 
@@ -14,7 +13,7 @@ const name = 'EscrowTerms.buyerSecret'
14
13
  * Returns a function that validates the escrow terms for buyerSecret
15
14
  * @returns A function that validates the escrow terms for buyerSecret
16
15
  */
17
- export const buyerSecretExistsValidator: PayloadValidationFunction<EscrowTerms> = (terms: EscrowTerms) => {
16
+ export const buyerSecretExistsValidator: SyncPayloadValidationFunction<EscrowTerms> = (terms: EscrowTerms) => {
18
17
  // Validate we have buyerSecret
19
18
  const buyerSecret = terms.buyerSecret
20
19
  if (!buyerSecret || buyerSecret.length === 0) {
@@ -29,7 +28,7 @@ export const buyerSecretExistsValidator: PayloadValidationFunction<EscrowTerms>
29
28
  * @param dictionary Payload dictionary of the escrow terms
30
29
  * @returns A function that validates the escrow terms for the existence of the buyerSecret in the dictionary
31
30
  */
32
- export const getBuyerSecretSuppliedValidator = (dictionary: Record<Hash, WithMeta<Payload>>): PayloadValidationFunction<EscrowTerms> => {
31
+ export const getBuyerSecretSuppliedValidator = (dictionary: Record<Hash, WithMeta<Payload>>): SyncPayloadValidationFunction<EscrowTerms> => {
33
32
  return (terms: EscrowTerms) => {
34
33
  const buyerSecret = assertEx(terms.buyerSecret, () => `${name}: No buyerSecret: ${terms.buyerSecret}`)
35
34
  if (!dictionary[buyerSecret]) {
@@ -45,32 +44,6 @@ export const getBuyerSecretSuppliedValidator = (dictionary: Record<Hash, WithMet
45
44
  * @param dictionary Payload dictionary of the escrow terms
46
45
  * @returns A function that validates the escrow terms for the existence of the buyerSecret signed by the buyer
47
46
  */
48
- export const getBuyerSecretSignedValidator = (dictionary: Record<Hash, WithMeta<Payload>>): PayloadValidationFunction<EscrowTerms> => {
49
- return async (terms: EscrowTerms) => {
50
- const buyer = assertEx(terms.buyer, () => `${name}: No buyer: ${terms.buyer}`)
51
- const buyerSecret = assertEx(terms.buyerSecret, () => `${name}: No buyerSecret: ${terms.buyerSecret}`)
52
- // Buyer-signed buyer secrets
53
- const buyerSecretBWs = Object.values(dictionary)
54
- // Find all BoundWitnesses
55
- .filter(isBoundWitnessWithMeta)
56
- // That contain the buyer secret
57
- .filter(bw => bw.payload_hashes.includes(buyerSecret))
58
- // That are signed by all the buyers
59
- .filter(bw => buyer.every(buyerAddress => bw.addresses.includes(buyerAddress)))
60
-
61
- // If there are no buyerSecret BWs, return false
62
- if (buyerSecretBWs.length === 0) {
63
- console.log(`${name}: No BoundWitnesses supplied for buyerSecret: ${buyerSecret}`)
64
- return false
65
- }
66
-
67
- // Ensure each BW supplied for the buyerSecret is valid
68
- const errors = await Promise.all(buyerSecretBWs.map(bw => new BoundWitnessValidator(bw).validate()))
69
- const validBoundWitnesses = errors.every(errors => errors.length === 0)
70
- if (!validBoundWitnesses) {
71
- console.log(`${name}: Invalid BoundWitnesses supplied for buyerSecret: ${buyerSecret}`)
72
- return false
73
- }
74
- return true
75
- }
47
+ export const getBuyerSecretSignedValidator = (dictionary: Record<Hash, WithMeta<Payload>>): AsyncPayloadValidationFunction<EscrowTerms> => {
48
+ return getPartySecretSignedValidator(dictionary, 'buyer')
76
49
  }
@@ -1,8 +1,8 @@
1
- import type { PayloadValidationFunction } from '@xyo-network/payload-model'
1
+ import type { SyncPayloadValidationFunction } from '@xyo-network/payload-model'
2
2
 
3
- import type { EscrowTerms } from '../../Terms.ts'
3
+ import type { EscrowTerms } from '../../Terms/index.ts'
4
4
 
5
- export const getNbfExpValidator = (now: number, minRequiredDuration: number): PayloadValidationFunction<EscrowTerms> => {
5
+ export const getNbfExpValidator = (now: number, minRequiredDuration: number): SyncPayloadValidationFunction<EscrowTerms> => {
6
6
  const minExp = now + minRequiredDuration
7
7
  return (terms: EscrowTerms) => {
8
8
  const { exp, nbf } = terms
@@ -1,12 +1,12 @@
1
1
  import type { ModuleIdentifier } from '@xyo-network/module-model'
2
- import type { PayloadValidationFunction } from '@xyo-network/payload-model'
2
+ import type { SyncPayloadValidationFunction } from '@xyo-network/payload-model'
3
3
 
4
- import type { EscrowTerms } from '../../Terms.ts'
4
+ import type { EscrowTerms } from '../../Terms/index.ts'
5
5
  import { moduleIdentifiersContainsAllOf } from '../common/index.ts'
6
6
 
7
7
  const name = 'EscrowTerms.paymentAuthorities'
8
8
 
9
- export const getPaymentAuthoritiesAllowedValidator = (allowed: ModuleIdentifier[]): PayloadValidationFunction<EscrowTerms> => {
9
+ export const getPaymentAuthoritiesAllowedValidator = (allowed: ModuleIdentifier[]): SyncPayloadValidationFunction<EscrowTerms> => {
10
10
  return (terms: EscrowTerms) => {
11
11
  const result = moduleIdentifiersContainsAllOf(terms, t => t.paymentAuthorities, allowed, true)
12
12
  if (!result) {
@@ -1,7 +1,7 @@
1
1
  import { asAddress } from '@xylabs/hex'
2
- import type { PayloadValidationFunction } from '@xyo-network/payload-model'
2
+ import type { SyncPayloadValidationFunction } from '@xyo-network/payload-model'
3
3
 
4
- import type { EscrowTerms } from '../../Terms.ts'
4
+ import type { EscrowTerms } from '../../Terms/index.ts'
5
5
 
6
6
  const name = 'EscrowTerms.seller'
7
7
 
@@ -9,7 +9,7 @@ const name = 'EscrowTerms.seller'
9
9
  * A function that validates the escrow terms for seller
10
10
  * @returns True if the escrow terms contain seller, false otherwise
11
11
  */
12
- export const sellerExistsValidator: PayloadValidationFunction<EscrowTerms> = (terms: EscrowTerms) => {
12
+ export const sellerExistsValidator: SyncPayloadValidationFunction<EscrowTerms> = (terms: EscrowTerms) => {
13
13
  // Validate we have seller
14
14
  const seller = terms.seller
15
15
  if (!seller || seller.length === 0) {
@@ -1,12 +1,11 @@
1
1
  import { assertEx } from '@xylabs/assert'
2
2
  import type { Hash } from '@xylabs/hex'
3
- import { isBoundWitnessWithMeta } from '@xyo-network/boundwitness-model'
4
- import { BoundWitnessValidator } from '@xyo-network/boundwitness-validator'
5
3
  import type {
6
- Payload, PayloadValidationFunction, WithMeta,
4
+ AsyncPayloadValidationFunction, Payload, SyncPayloadValidationFunction, WithMeta,
7
5
  } from '@xyo-network/payload-model'
8
6
 
9
- import type { EscrowTerms } from '../../Terms.ts'
7
+ import type { EscrowTerms } from '../../Terms/index.ts'
8
+ import { getPartySecretSignedValidator } from '../common/index.ts'
10
9
 
11
10
  const name = 'EscrowTerms.sellerSecret'
12
11
 
@@ -14,7 +13,7 @@ const name = 'EscrowTerms.sellerSecret'
14
13
  * Returns a function that validates the escrow terms for sellerSecret
15
14
  * @returns A function that validates the escrow terms for sellerSecret
16
15
  */
17
- export const sellerSecretExistsValidator: PayloadValidationFunction<EscrowTerms> = (terms: EscrowTerms) => {
16
+ export const sellerSecretExistsValidator: SyncPayloadValidationFunction<EscrowTerms> = (terms: EscrowTerms) => {
18
17
  // Validate we have sellerSecret
19
18
  const sellerSecret = terms.sellerSecret
20
19
  if (!sellerSecret || sellerSecret.length === 0) {
@@ -29,7 +28,7 @@ export const sellerSecretExistsValidator: PayloadValidationFunction<EscrowTerms>
29
28
  * @param dictionary Payload dictionary of the escrow terms
30
29
  * @returns A function that validates the escrow terms for the existence of the sellerSecret in the dictionary
31
30
  */
32
- export const getSellerSecretSuppliedValidator = (dictionary: Record<Hash, WithMeta<Payload>>): PayloadValidationFunction<EscrowTerms> => {
31
+ export const getSellerSecretSuppliedValidator = (dictionary: Record<Hash, WithMeta<Payload>>): SyncPayloadValidationFunction<EscrowTerms> => {
33
32
  return (terms: EscrowTerms) => {
34
33
  const sellerSecret = assertEx(terms.sellerSecret, () => `${name}: No sellerSecret: ${terms.sellerSecret}`)
35
34
  if (!dictionary[sellerSecret]) {
@@ -45,32 +44,6 @@ export const getSellerSecretSuppliedValidator = (dictionary: Record<Hash, WithMe
45
44
  * @param dictionary Payload dictionary of the escrow terms
46
45
  * @returns A function that validates the escrow terms for the existence of the sellerSecret signed by the seller
47
46
  */
48
- export const getSellerSecretSignedValidator = (dictionary: Record<Hash, WithMeta<Payload>>): PayloadValidationFunction<EscrowTerms> => {
49
- return async (terms: EscrowTerms) => {
50
- const seller = assertEx(terms.seller, () => `${name}: No seller: ${terms.seller}`)
51
- const sellerSecret = assertEx(terms.sellerSecret, () => `${name}: No sellerSecret: ${terms.sellerSecret}`)
52
- // Seller-signed seller secrets
53
- const sellerSecretBWs = Object.values(dictionary)
54
- // Find all BoundWitnesses
55
- .filter(isBoundWitnessWithMeta)
56
- // That contain the seller secret
57
- .filter(bw => bw.payload_hashes.includes(sellerSecret))
58
- // That are signed by all the sellers
59
- .filter(bw => seller.every(sellerAddress => bw.addresses.includes(sellerAddress)))
60
-
61
- // If there are no sellerSecret BWs, return false
62
- if (sellerSecretBWs.length === 0) {
63
- console.log(`${name}: No BoundWitnesses supplied for sellerSecret: ${sellerSecret}`)
64
- return false
65
- }
66
-
67
- // Ensure each BW supplied for the sellerSecret is valid
68
- const errors = await Promise.all(sellerSecretBWs.map(bw => new BoundWitnessValidator(bw).validate()))
69
- const validBoundWitnesses = errors.every(errors => errors.length === 0)
70
- if (!validBoundWitnesses) {
71
- console.log(`${name}: Invalid BoundWitnesses supplied for sellerSecret: ${sellerSecret}`)
72
- return false
73
- }
74
- return true
75
- }
47
+ export const getSellerSecretSignedValidator = (dictionary: Record<Hash, WithMeta<Payload>>): AsyncPayloadValidationFunction<EscrowTerms> => {
48
+ return getPartySecretSignedValidator(dictionary, 'seller')
76
49
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"Terms.d.ts","sourceRoot":"","sources":["../../../src/Escrow/Terms.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAOzD,eAAO,MAAM,iBAAiB,4BAAmC,CAAA;AACjE,MAAM,MAAM,iBAAiB,GAAG,OAAO,iBAAiB,CAAA;AAGxD,MAAM,WAAW,iBAAiB;IAIhC,oBAAoB,EAAE,OAAO,EAAE,CAAA;IAI/B,UAAU,EAAE,IAAI,EAAE,CAAA;IAIlB,MAAM,EAAE,IAAI,EAAE,CAAA;IAId,KAAK,EAAE,OAAO,EAAE,CAAA;IAIhB,WAAW,EAAE,IAAI,CAAA;IAIjB,SAAS,EAAE,IAAI,EAAE,CAAA;IAIjB,WAAW,EAAE,OAAO,CAAA;IAIpB,GAAG,EAAE,MAAM,CAAA;IAIX,GAAG,EAAE,MAAM,CAAA;IAIX,kBAAkB,EAAE,OAAO,EAAE,CAAA;IAI7B,MAAM,EAAE,OAAO,EAAE,CAAA;IAIjB,YAAY,EAAE,IAAI,CAAA;CACnB;AAKD,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,CAAC,CAAA;AAKhF,eAAO,MAAM,aAAa;;CAAwD,CAAA;AAKlF,eAAO,MAAM,wBAAwB;;EAAmE,CAAA;AAKxG,eAAO,MAAM,qBAAqB;;EAAgE,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"createEscrowIntent.d.ts","sourceRoot":"","sources":["../../../src/Escrow/createEscrowIntent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAEjE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAA;AAE/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAS7C,eAAO,MAAM,kBAAkB,UAAiB,WAAW,EAAE,WAAW,eAAe;;;;;;;;;;;MAGtF,CAAA;AASD,eAAO,MAAM,4BAA4B,UAAiB,WAAW,UAAU,SAAS,WAAW,eAAe;;;;;;;;;;;MAGjH,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"getEscrowSecret.d.ts","sourceRoot":"","sources":["../../../src/Escrow/getEscrowSecret.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAA;AAO/D,eAAO,MAAM,eAAe,QAAO,SAElC,CAAA"}