@xyo-network/payment-payload-plugins 4.1.1 → 5.0.0
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/Amount/Payload.d.ts.map +1 -1
- package/dist/neutral/Billing/Address/Address.d.ts +2 -2
- package/dist/neutral/Billing/Address/Address.d.ts.map +1 -1
- package/dist/neutral/Discount/Payload/Coupon/Coupons/FixedAmount.d.ts +2 -2
- package/dist/neutral/Discount/Payload/Coupon/Coupons/FixedAmount.d.ts.map +1 -1
- package/dist/neutral/Discount/Payload/Coupon/Coupons/FixedPercentage.d.ts +2 -2
- package/dist/neutral/Discount/Payload/Coupon/Coupons/FixedPercentage.d.ts.map +1 -1
- package/dist/neutral/Discount/Payload/Coupon/Coupons/FixedPrice.d.ts +2 -2
- package/dist/neutral/Discount/Payload/Coupon/Coupons/FixedPrice.d.ts.map +1 -1
- package/dist/neutral/Discount/Payload/Discount.d.ts +2 -2
- package/dist/neutral/Discount/Payload/Discount.d.ts.map +1 -1
- package/dist/neutral/Escrow/Outcome.d.ts +3 -3
- package/dist/neutral/Escrow/Outcome.d.ts.map +1 -1
- package/dist/neutral/Escrow/Terms/Terms.d.ts +2 -2
- package/dist/neutral/Escrow/Terms/Terms.d.ts.map +1 -1
- package/dist/neutral/Payment/Instrument/Card/Payload.d.ts +2 -2
- package/dist/neutral/Payment/Instrument/Card/Payload.d.ts.map +1 -1
- package/dist/neutral/Payment/Payload.d.ts +2 -2
- package/dist/neutral/Payment/Payload.d.ts.map +1 -1
- package/dist/neutral/Payment/Status/Payload.d.ts +2 -2
- package/dist/neutral/Payment/Status/Payload.d.ts.map +1 -1
- package/dist/neutral/Purchase/Payload.d.ts +2 -2
- package/dist/neutral/Purchase/Payload.d.ts.map +1 -1
- package/dist/neutral/Receipt/Payload.d.ts +2 -2
- package/dist/neutral/Receipt/Payload.d.ts.map +1 -1
- package/dist/neutral/Subtotal/Diviner/Payload.d.ts +2 -2
- package/dist/neutral/Subtotal/Diviner/Payload.d.ts.map +1 -1
- package/dist/neutral/Total/Diviner/Payload.d.ts +2 -2
- package/dist/neutral/Total/Diviner/Payload.d.ts.map +1 -1
- package/dist/neutral/index.d.ts +12 -850
- package/package.json +26 -23
- package/src/Escrow/validators/common/ModuleInstanceValidators/spec/moduleInstanceValidators.spec.ts +79 -0
- package/src/Escrow/validators/common/SecretValidators/spec/getPartySecretSignedValidator.spec.ts +91 -0
- package/typedoc.json +0 -5
- package/xy.config.ts +0 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/payment-payload-plugins",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Typescript/Javascript Plugins for XYO Platform",
|
|
5
5
|
"homepage": "https://xyo.network",
|
|
6
6
|
"bugs": {
|
|
@@ -28,31 +28,34 @@
|
|
|
28
28
|
},
|
|
29
29
|
"module": "dist/neutral/index.mjs",
|
|
30
30
|
"types": "dist/neutral/index.d.ts",
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"src"
|
|
34
|
+
],
|
|
31
35
|
"dependencies": {
|
|
32
|
-
"@xylabs/assert": "^
|
|
33
|
-
"@xylabs/crypto": "^
|
|
34
|
-
"@xylabs/hex": "^
|
|
35
|
-
"@xylabs/object": "^
|
|
36
|
-
"@xyo-network/account-model": "^
|
|
37
|
-
"@xyo-network/boundwitness-builder": "^
|
|
38
|
-
"@xyo-network/boundwitness-model": "^
|
|
39
|
-
"@xyo-network/boundwitness-validator": "^
|
|
40
|
-
"@xyo-network/diviner-hash-lease": "^
|
|
41
|
-
"@xyo-network/diviner-model": "^
|
|
42
|
-
"@xyo-network/id-payload-plugin": "^
|
|
43
|
-
"@xyo-network/module-model": "^
|
|
44
|
-
"@xyo-network/payload-builder": "^
|
|
45
|
-
"@xyo-network/payload-model": "^
|
|
46
|
-
"@xyo-network/schema-payload-plugin": "^
|
|
47
|
-
"@xyo-network/xns-record-payload-plugins": "^
|
|
36
|
+
"@xylabs/assert": "^5.0.0",
|
|
37
|
+
"@xylabs/crypto": "^5.0.0",
|
|
38
|
+
"@xylabs/hex": "^5.0.0",
|
|
39
|
+
"@xylabs/object": "^5.0.0",
|
|
40
|
+
"@xyo-network/account-model": "^5.0.0",
|
|
41
|
+
"@xyo-network/boundwitness-builder": "^5.0.0",
|
|
42
|
+
"@xyo-network/boundwitness-model": "^5.0.0",
|
|
43
|
+
"@xyo-network/boundwitness-validator": "^5.0.0",
|
|
44
|
+
"@xyo-network/diviner-hash-lease": "^5.0.0",
|
|
45
|
+
"@xyo-network/diviner-model": "^5.0.0",
|
|
46
|
+
"@xyo-network/id-payload-plugin": "^5.0.0",
|
|
47
|
+
"@xyo-network/module-model": "^5.0.0",
|
|
48
|
+
"@xyo-network/payload-builder": "^5.0.0",
|
|
49
|
+
"@xyo-network/payload-model": "^5.0.0",
|
|
50
|
+
"@xyo-network/schema-payload-plugin": "^5.0.0",
|
|
51
|
+
"@xyo-network/xns-record-payload-plugins": "^5.0.0"
|
|
48
52
|
},
|
|
49
53
|
"devDependencies": {
|
|
50
|
-
"@xylabs/ts-scripts-yarn3": "^7.0.
|
|
51
|
-
"@xylabs/tsconfig": "^7.0.
|
|
52
|
-
"@xylabs/vitest-extended": "^
|
|
53
|
-
"@xyo-network/payload-builder": "^
|
|
54
|
-
"@xyo-network/wallet": "^
|
|
55
|
-
"knip": "^5.62.0",
|
|
54
|
+
"@xylabs/ts-scripts-yarn3": "^7.0.2",
|
|
55
|
+
"@xylabs/tsconfig": "^7.0.2",
|
|
56
|
+
"@xylabs/vitest-extended": "^5.0.0",
|
|
57
|
+
"@xyo-network/payload-builder": "^5.0.0",
|
|
58
|
+
"@xyo-network/wallet": "^5.0.0",
|
|
56
59
|
"typescript": "^5.8.3",
|
|
57
60
|
"vitest": "^3.2.4"
|
|
58
61
|
},
|
package/src/Escrow/validators/common/ModuleInstanceValidators/spec/moduleInstanceValidators.spec.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import '@xylabs/vitest-extended'
|
|
2
|
+
|
|
3
|
+
import type { Address } from '@xylabs/hex'
|
|
4
|
+
import type { ModuleIdentifier } from '@xyo-network/module-model'
|
|
5
|
+
import {
|
|
6
|
+
describe, expect, test,
|
|
7
|
+
} from 'vitest'
|
|
8
|
+
|
|
9
|
+
import type { EscrowTerms } from '../../../../Terms/index.ts'
|
|
10
|
+
import { EscrowTermsSchema } from '../../../../Terms/index.ts'
|
|
11
|
+
import { moduleIdentifiersContainsOneOf } from '../moduleInstanceValidators.ts'
|
|
12
|
+
|
|
13
|
+
describe('RegistrarSentinel', () => {
|
|
14
|
+
const appraisalAuthority1 = 'address1' as Address
|
|
15
|
+
const appraisalAuthority2 = 'address2' as Address
|
|
16
|
+
const buyer1 = 'address3' as Address
|
|
17
|
+
const escrowAgent = 'address4' as Address
|
|
18
|
+
const paymentAuthority1 = 'address5' as Address
|
|
19
|
+
const seller1 = 'address6' as Address
|
|
20
|
+
const escrowTermsExample: EscrowTerms = {
|
|
21
|
+
appraisalAuthorities: [appraisalAuthority1, appraisalAuthority2],
|
|
22
|
+
buyer: [buyer1],
|
|
23
|
+
escrowAgent: escrowAgent,
|
|
24
|
+
paymentAuthorities: [paymentAuthority1],
|
|
25
|
+
schema: EscrowTermsSchema,
|
|
26
|
+
seller: [seller1],
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const moduleIdentifiersExample: ModuleIdentifier[] = [appraisalAuthority1, 'randomAddress', escrowAgent, paymentAuthority1]
|
|
30
|
+
|
|
31
|
+
describe('moduleIdentifiersContainsOneOf', () => {
|
|
32
|
+
// Positive test for scalar value
|
|
33
|
+
test('returns true for a matching scalar value', () => {
|
|
34
|
+
const result = moduleIdentifiersContainsOneOf(escrowTermsExample, terms => terms.escrowAgent, moduleIdentifiersExample)
|
|
35
|
+
expect(result).toBeTruthy()
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
// Negative test for scalar value
|
|
39
|
+
test('returns false for a non-matching scalar value', () => {
|
|
40
|
+
const result = moduleIdentifiersContainsOneOf(escrowTermsExample, terms => terms.buyer, moduleIdentifiersExample)
|
|
41
|
+
expect(result).toBeFalsy()
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
// Positive test for array values
|
|
45
|
+
test('returns true when at least one array value matches', () => {
|
|
46
|
+
const result = moduleIdentifiersContainsOneOf(escrowTermsExample, terms => terms.appraisalAuthorities, moduleIdentifiersExample)
|
|
47
|
+
expect(result).toBeTruthy()
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
// Negative test for array values
|
|
51
|
+
test('returns false when no array values match', () => {
|
|
52
|
+
const nonMatchingModuleIdentifiers: ModuleIdentifier[] = ['nonMatching1', 'nonMatching2']
|
|
53
|
+
const result = moduleIdentifiersContainsOneOf(escrowTermsExample, terms => terms.appraisalAuthorities, nonMatchingModuleIdentifiers)
|
|
54
|
+
expect(result).toBeFalsy()
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
// Test for required parameter when termsValue is undefined
|
|
58
|
+
test('returns false when termsValue is undefined and required is true', () => {
|
|
59
|
+
const result = moduleIdentifiersContainsOneOf(
|
|
60
|
+
{ schema: EscrowTermsSchema }, // Empty object, no terms defined
|
|
61
|
+
terms => terms.buyer, // This will be undefined
|
|
62
|
+
moduleIdentifiersExample,
|
|
63
|
+
true, // Explicitly stating required is true
|
|
64
|
+
)
|
|
65
|
+
expect(result).toBeFalsy()
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
// Test for not required parameter when termsValue is undefined
|
|
69
|
+
test('returns true when termsValue is undefined and required is false', () => {
|
|
70
|
+
const result = moduleIdentifiersContainsOneOf(
|
|
71
|
+
{ schema: EscrowTermsSchema }, // Empty object, no terms defined
|
|
72
|
+
terms => terms.buyer, // This will be undefined
|
|
73
|
+
moduleIdentifiersExample,
|
|
74
|
+
false, // Required is false
|
|
75
|
+
)
|
|
76
|
+
expect(result).toBeTruthy()
|
|
77
|
+
})
|
|
78
|
+
})
|
|
79
|
+
})
|
package/src/Escrow/validators/common/SecretValidators/spec/getPartySecretSignedValidator.spec.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/* eslint-disable max-nested-callbacks */
|
|
2
|
+
import '@xylabs/vitest-extended'
|
|
3
|
+
|
|
4
|
+
import type { AccountInstance } from '@xyo-network/account-model'
|
|
5
|
+
import type { BoundWitness } from '@xyo-network/boundwitness-model'
|
|
6
|
+
import type { Id } from '@xyo-network/id-payload-plugin'
|
|
7
|
+
import { IdSchema } from '@xyo-network/id-payload-plugin'
|
|
8
|
+
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
9
|
+
import type { Payload } from '@xyo-network/payload-model'
|
|
10
|
+
import { HDWallet } from '@xyo-network/wallet'
|
|
11
|
+
import {
|
|
12
|
+
beforeAll,
|
|
13
|
+
describe, expect, it,
|
|
14
|
+
} from 'vitest'
|
|
15
|
+
|
|
16
|
+
import type { EscrowParty, EscrowTerms } from '../../../../Terms/index.ts'
|
|
17
|
+
import { EscrowTermsSchema } from '../../../../Terms/index.ts'
|
|
18
|
+
import { createEscrowIntentWithSecret } from '../../../../util/index.ts'
|
|
19
|
+
import { getPartySecretSignedValidator } from '../getPartySecretSignedValidator.ts'
|
|
20
|
+
|
|
21
|
+
describe('RegistrarSentinel', () => {
|
|
22
|
+
let buyer: AccountInstance
|
|
23
|
+
let seller: AccountInstance
|
|
24
|
+
const baseTerms: EscrowTerms = { schema: EscrowTermsSchema }
|
|
25
|
+
const buyerSecret: Id = { schema: IdSchema, salt: `${Date.now() - 10}` }
|
|
26
|
+
let buyerSecretSignature: BoundWitness
|
|
27
|
+
const sellerSecret: Id = { schema: IdSchema, salt: `${Date.now() + 10}` }
|
|
28
|
+
let sellerSecretSignature: BoundWitness
|
|
29
|
+
|
|
30
|
+
describe('getPartySecretSignedValidator', () => {
|
|
31
|
+
beforeAll(async () => {
|
|
32
|
+
buyer = await HDWallet.random()
|
|
33
|
+
seller = await HDWallet.random()
|
|
34
|
+
|
|
35
|
+
baseTerms.buyer = [buyer.address]
|
|
36
|
+
baseTerms.buyerSecret = await PayloadBuilder.dataHash(buyerSecret)
|
|
37
|
+
baseTerms.seller = [seller.address]
|
|
38
|
+
baseTerms.sellerSecret = await PayloadBuilder.dataHash(sellerSecret)
|
|
39
|
+
|
|
40
|
+
const buyerIntent = await createEscrowIntentWithSecret(baseTerms, buyerSecret, buyer)
|
|
41
|
+
const sellerIntent = await createEscrowIntentWithSecret(baseTerms, sellerSecret, seller)
|
|
42
|
+
|
|
43
|
+
buyerSecretSignature = buyerIntent[0]
|
|
44
|
+
sellerSecretSignature = sellerIntent[0]
|
|
45
|
+
})
|
|
46
|
+
const cases: EscrowParty[] = ['buyer', 'seller']
|
|
47
|
+
describe.each(cases)('for %s', (party) => {
|
|
48
|
+
describe('returns true', () => {
|
|
49
|
+
it('with valid escrow terms and values supplied', async () => {
|
|
50
|
+
const payloads = party === 'buyer' ? [baseTerms, buyerSecret, buyerSecretSignature] : [baseTerms, sellerSecret, sellerSecretSignature]
|
|
51
|
+
const dictionary = await PayloadBuilder.toAllHashMap(payloads)
|
|
52
|
+
const partySecretValidator = getPartySecretSignedValidator(dictionary, party)
|
|
53
|
+
const result = await partySecretValidator(baseTerms)
|
|
54
|
+
expect(result).toBeTrue()
|
|
55
|
+
})
|
|
56
|
+
})
|
|
57
|
+
describe('returns false', () => {
|
|
58
|
+
describe('with invalid escrow terms value for', () => {
|
|
59
|
+
describe('secret', () => {
|
|
60
|
+
it('undefined', async () => {
|
|
61
|
+
const terms = { ...baseTerms, [`${party}Secret`]: undefined }
|
|
62
|
+
const payloads = party === 'buyer' ? [terms, buyerSecret, buyerSecretSignature] : [terms, sellerSecret, sellerSecretSignature]
|
|
63
|
+
const dictionary = await PayloadBuilder.toAllHashMap(payloads)
|
|
64
|
+
const partySecretValidator = getPartySecretSignedValidator(dictionary, party)
|
|
65
|
+
const result = await partySecretValidator(terms)
|
|
66
|
+
expect(result).toBeFalse()
|
|
67
|
+
})
|
|
68
|
+
it('different from signature', async () => {
|
|
69
|
+
const secret: Id = { schema: IdSchema, salt: '0' }
|
|
70
|
+
const terms = { ...baseTerms, [`${party}Secret`]: await PayloadBuilder.dataHash(secret) }
|
|
71
|
+
const payloads = party === 'buyer' ? [terms, buyerSecret, buyerSecretSignature] : [terms, sellerSecret, sellerSecretSignature]
|
|
72
|
+
const dictionary = await PayloadBuilder.toAllHashMap(payloads)
|
|
73
|
+
const partySecretValidator = getPartySecretSignedValidator(dictionary, party)
|
|
74
|
+
const result = await partySecretValidator(terms)
|
|
75
|
+
expect(result).toBeFalse()
|
|
76
|
+
})
|
|
77
|
+
})
|
|
78
|
+
})
|
|
79
|
+
describe('with missing value for', () => {
|
|
80
|
+
it('boundwitness', async () => {
|
|
81
|
+
const payloads: Payload[] = party === 'buyer' ? [baseTerms, buyerSecret] : [baseTerms, sellerSecret]
|
|
82
|
+
const dictionary = await PayloadBuilder.toAllHashMap(payloads)
|
|
83
|
+
const partySecretValidator = getPartySecretSignedValidator(dictionary, party)
|
|
84
|
+
const result = await partySecretValidator(baseTerms)
|
|
85
|
+
expect(result).toBeFalse()
|
|
86
|
+
})
|
|
87
|
+
})
|
|
88
|
+
})
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
})
|
package/typedoc.json
DELETED