@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.
- package/dist/browser/Escrow/validators/escrow/index.d.cts +1 -0
- package/dist/browser/Escrow/validators/escrow/index.d.cts.map +1 -1
- package/dist/browser/Escrow/validators/escrow/index.d.mts +1 -0
- package/dist/browser/Escrow/validators/escrow/index.d.mts.map +1 -1
- package/dist/browser/Escrow/validators/escrow/index.d.ts +1 -0
- package/dist/browser/Escrow/validators/escrow/index.d.ts.map +1 -1
- package/dist/browser/Escrow/validators/escrow/sellerSecret.d.cts +21 -0
- package/dist/browser/Escrow/validators/escrow/sellerSecret.d.cts.map +1 -0
- package/dist/browser/Escrow/validators/escrow/sellerSecret.d.mts +21 -0
- package/dist/browser/Escrow/validators/escrow/sellerSecret.d.mts.map +1 -0
- package/dist/browser/Escrow/validators/escrow/sellerSecret.d.ts +21 -0
- package/dist/browser/Escrow/validators/escrow/sellerSecret.d.ts.map +1 -0
- package/dist/browser/index.cjs +47 -2
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +45 -0
- package/dist/browser/index.js.map +1 -1
- package/dist/node/Escrow/validators/escrow/index.d.cts +1 -0
- package/dist/node/Escrow/validators/escrow/index.d.cts.map +1 -1
- package/dist/node/Escrow/validators/escrow/index.d.mts +1 -0
- package/dist/node/Escrow/validators/escrow/index.d.mts.map +1 -1
- package/dist/node/Escrow/validators/escrow/index.d.ts +1 -0
- package/dist/node/Escrow/validators/escrow/index.d.ts.map +1 -1
- package/dist/node/Escrow/validators/escrow/sellerSecret.d.cts +21 -0
- package/dist/node/Escrow/validators/escrow/sellerSecret.d.cts.map +1 -0
- package/dist/node/Escrow/validators/escrow/sellerSecret.d.mts +21 -0
- package/dist/node/Escrow/validators/escrow/sellerSecret.d.mts.map +1 -0
- package/dist/node/Escrow/validators/escrow/sellerSecret.d.ts +21 -0
- package/dist/node/Escrow/validators/escrow/sellerSecret.d.ts.map +1 -0
- package/dist/node/index.cjs +50 -2
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +45 -0
- package/dist/node/index.js.map +1 -1
- package/package.json +9 -9
- package/src/Escrow/validators/escrow/index.ts +1 -0
- 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.
|
|
17
|
-
"@xyo-network/boundwitness-builder": "^2.94.
|
|
18
|
-
"@xyo-network/boundwitness-model": "^2.94.
|
|
19
|
-
"@xyo-network/boundwitness-validator": "^2.94.
|
|
20
|
-
"@xyo-network/diviner-hash-lease": "^2.94.
|
|
21
|
-
"@xyo-network/id-payload-plugin": "^2.94.
|
|
22
|
-
"@xyo-network/module-model": "^2.94.
|
|
23
|
-
"@xyo-network/payload-model": "^2.94.
|
|
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.
|
|
69
|
+
"version": "2.91.7",
|
|
70
70
|
"type": "module"
|
|
71
71
|
}
|
|
@@ -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
|
+
}
|