@xyo-network/payment-payload-plugins 2.91.6 → 2.91.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/browser/Escrow/validators/escrow/index.d.cts +1 -0
  2. package/dist/browser/Escrow/validators/escrow/index.d.cts.map +1 -1
  3. package/dist/browser/Escrow/validators/escrow/index.d.mts +1 -0
  4. package/dist/browser/Escrow/validators/escrow/index.d.mts.map +1 -1
  5. package/dist/browser/Escrow/validators/escrow/index.d.ts +1 -0
  6. package/dist/browser/Escrow/validators/escrow/index.d.ts.map +1 -1
  7. package/dist/browser/Escrow/validators/escrow/sellerSecret.d.cts +21 -0
  8. package/dist/browser/Escrow/validators/escrow/sellerSecret.d.cts.map +1 -0
  9. package/dist/browser/Escrow/validators/escrow/sellerSecret.d.mts +21 -0
  10. package/dist/browser/Escrow/validators/escrow/sellerSecret.d.mts.map +1 -0
  11. package/dist/browser/Escrow/validators/escrow/sellerSecret.d.ts +21 -0
  12. package/dist/browser/Escrow/validators/escrow/sellerSecret.d.ts.map +1 -0
  13. package/dist/browser/index.cjs +47 -2
  14. package/dist/browser/index.cjs.map +1 -1
  15. package/dist/browser/index.js +45 -0
  16. package/dist/browser/index.js.map +1 -1
  17. package/dist/node/Escrow/validators/escrow/index.d.cts +1 -0
  18. package/dist/node/Escrow/validators/escrow/index.d.cts.map +1 -1
  19. package/dist/node/Escrow/validators/escrow/index.d.mts +1 -0
  20. package/dist/node/Escrow/validators/escrow/index.d.mts.map +1 -1
  21. package/dist/node/Escrow/validators/escrow/index.d.ts +1 -0
  22. package/dist/node/Escrow/validators/escrow/index.d.ts.map +1 -1
  23. package/dist/node/Escrow/validators/escrow/sellerSecret.d.cts +21 -0
  24. package/dist/node/Escrow/validators/escrow/sellerSecret.d.cts.map +1 -0
  25. package/dist/node/Escrow/validators/escrow/sellerSecret.d.mts +21 -0
  26. package/dist/node/Escrow/validators/escrow/sellerSecret.d.mts.map +1 -0
  27. package/dist/node/Escrow/validators/escrow/sellerSecret.d.ts +21 -0
  28. package/dist/node/Escrow/validators/escrow/sellerSecret.d.ts.map +1 -0
  29. package/dist/node/index.cjs +50 -2
  30. package/dist/node/index.cjs.map +1 -1
  31. package/dist/node/index.js +45 -0
  32. package/dist/node/index.js.map +1 -1
  33. package/package.json +9 -9
  34. package/src/Escrow/validators/escrow/index.ts +1 -0
  35. package/src/Escrow/validators/escrow/sellerSecret.ts +75 -0
package/package.json CHANGED
@@ -13,14 +13,14 @@
13
13
  "@xylabs/assert": "^3.0.25",
14
14
  "@xylabs/crypto": "^3.0.25",
15
15
  "@xylabs/hex": "^3.0.25",
16
- "@xyo-network/account-model": "^2.94.11",
17
- "@xyo-network/boundwitness-builder": "^2.94.11",
18
- "@xyo-network/boundwitness-model": "^2.94.11",
19
- "@xyo-network/boundwitness-validator": "^2.94.11",
20
- "@xyo-network/diviner-hash-lease": "^2.94.11",
21
- "@xyo-network/id-payload-plugin": "^2.94.11",
22
- "@xyo-network/module-model": "^2.94.11",
23
- "@xyo-network/payload-model": "^2.94.11"
16
+ "@xyo-network/account-model": "^2.94.12",
17
+ "@xyo-network/boundwitness-builder": "^2.94.12",
18
+ "@xyo-network/boundwitness-model": "^2.94.12",
19
+ "@xyo-network/boundwitness-validator": "^2.94.12",
20
+ "@xyo-network/diviner-hash-lease": "^2.94.12",
21
+ "@xyo-network/id-payload-plugin": "^2.94.12",
22
+ "@xyo-network/module-model": "^2.94.12",
23
+ "@xyo-network/payload-model": "^2.94.12"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@xylabs/ts-scripts-yarn3": "^3.9.0",
@@ -66,6 +66,6 @@
66
66
  "url": "https://github.com/XYOracleNetwork/plugins.git"
67
67
  },
68
68
  "sideEffects": false,
69
- "version": "2.91.6",
69
+ "version": "2.91.7",
70
70
  "type": "module"
71
71
  }
@@ -7,3 +7,4 @@ export * from './buyerSecret'
7
7
  export * from './nbfExp'
8
8
  export * from './paymentAuthorities'
9
9
  export * from './seller'
10
+ export * from './sellerSecret'
@@ -0,0 +1,75 @@
1
+ import { assertEx } from '@xylabs/assert'
2
+ import { Hash } from '@xylabs/hex'
3
+ import { isBoundWitnessWithMeta } from '@xyo-network/boundwitness-model'
4
+ import { BoundWitnessValidator } from '@xyo-network/boundwitness-validator'
5
+ import { Payload, WithMeta } from '@xyo-network/payload-model'
6
+
7
+ import { EscrowTerms } from '../../Terms'
8
+ import { EscrowTermsValidationFunction } from '../types'
9
+
10
+ const name = 'EscrowTerms.sellerSecret'
11
+
12
+ /**
13
+ * Returns a function that validates the escrow terms for sellerSecret
14
+ * @returns A function that validates the escrow terms for sellerSecret
15
+ */
16
+ export const sellerSecretExistsValidator: EscrowTermsValidationFunction = (terms: EscrowTerms) => {
17
+ // Validate we have sellerSecret
18
+ const sellerSecret = terms.sellerSecret
19
+ if (!sellerSecret || sellerSecret.length === 0) {
20
+ console.log(`${name}: No sellerSecret: ${terms.sellerSecret}`)
21
+ return false
22
+ }
23
+ return true
24
+ }
25
+
26
+ /**
27
+ * Returns a function that validates the escrow terms for the existence of the sellerSecret in the dictionary
28
+ * @param dictionary Payload dictionary of the escrow terms
29
+ * @returns A function that validates the escrow terms for the existence of the sellerSecret in the dictionary
30
+ */
31
+ export const getSellerSecretSuppliedValidator = (dictionary: Record<Hash, WithMeta<Payload>>): EscrowTermsValidationFunction => {
32
+ return (terms: EscrowTerms) => {
33
+ const sellerSecret = assertEx(terms.sellerSecret, () => `${name}: No sellerSecret: ${terms.sellerSecret}`)
34
+ if (!dictionary[sellerSecret]) {
35
+ console.log(`${name}: Payload not supplied for sellerSecret: ${sellerSecret}`)
36
+ return false
37
+ }
38
+ return true
39
+ }
40
+ }
41
+
42
+ /**
43
+ * Returns a function that validates the escrow terms for the existence of the sellerSecret signed by the seller
44
+ * @param dictionary Payload dictionary of the escrow terms
45
+ * @returns A function that validates the escrow terms for the existence of the sellerSecret signed by the seller
46
+ */
47
+ export const getSellerSecretSignedValidator = (dictionary: Record<Hash, WithMeta<Payload>>): EscrowTermsValidationFunction => {
48
+ return async (terms: EscrowTerms) => {
49
+ const seller = assertEx(terms.seller, () => `${name}: No seller: ${terms.seller}`)
50
+ const sellerSecret = assertEx(terms.sellerSecret, () => `${name}: No sellerSecret: ${terms.sellerSecret}`)
51
+ // Seller-signed seller secrets
52
+ const sellerSecretBWs = Object.values(dictionary)
53
+ // Find all BoundWitnesses
54
+ .filter(isBoundWitnessWithMeta)
55
+ // That contain the seller secret
56
+ .filter((bw) => bw.payload_hashes.includes(sellerSecret))
57
+ // That are signed by all the sellers
58
+ .filter((bw) => seller.every((sellerAddress) => bw.addresses.includes(sellerAddress)))
59
+
60
+ // If there are no sellerSecret BWs, return false
61
+ if (sellerSecretBWs.length === 0) {
62
+ console.log(`${name}: No BoundWitnesses supplied for sellerSecret: ${sellerSecret}`)
63
+ return false
64
+ }
65
+
66
+ // Ensure each BW supplied for the sellerSecret is valid
67
+ const errors = await Promise.all(sellerSecretBWs.map((bw) => new BoundWitnessValidator(bw).validate()))
68
+ const validBoundWitnesses = errors.every((errors) => errors.length === 0)
69
+ if (!validBoundWitnesses) {
70
+ console.log(`${name}: Invalid BoundWitnesses supplied for sellerSecret: ${sellerSecret}`)
71
+ return false
72
+ }
73
+ return true
74
+ }
75
+ }