From cf32f6f0efcdc6b39a5b43ae8f4921ff5d6c3039 Mon Sep 17 00:00:00 2001 From: Matt Jones <885417+jonesmac@users.noreply.github.com> Date: Tue, 3 Sep 2024 16:54:17 -0400 Subject: [PATCH 01/46] stub package with validators --- .../record/src/validation/private/index.ts | 1 + .../src/validation/private/validators.ts | 48 ++++++ .../record/src/validation/public/index.ts | 1 + .../src/validation/public/validators.ts | 77 +++++++++ .../record/src/validation/spec/tsconfig.json | 13 ++ .../src/validation/spec/validators.spec.ts | 159 ++++++++++++++++++ 6 files changed, 299 insertions(+) create mode 100644 packages/payload/packages/xns/plugins/record/src/validation/private/index.ts create mode 100644 packages/payload/packages/xns/plugins/record/src/validation/private/validators.ts create mode 100644 packages/payload/packages/xns/plugins/record/src/validation/public/index.ts create mode 100644 packages/payload/packages/xns/plugins/record/src/validation/public/validators.ts create mode 100644 packages/payload/packages/xns/plugins/record/src/validation/spec/tsconfig.json create mode 100644 packages/payload/packages/xns/plugins/record/src/validation/spec/validators.spec.ts diff --git a/packages/payload/packages/xns/plugins/record/src/validation/private/index.ts b/packages/payload/packages/xns/plugins/record/src/validation/private/index.ts new file mode 100644 index 000000000..804263de1 --- /dev/null +++ b/packages/payload/packages/xns/plugins/record/src/validation/private/index.ts @@ -0,0 +1 @@ +export * from './validators.ts' diff --git a/packages/payload/packages/xns/plugins/record/src/validation/private/validators.ts b/packages/payload/packages/xns/plugins/record/src/validation/private/validators.ts new file mode 100644 index 000000000..7ffb10691 --- /dev/null +++ b/packages/payload/packages/xns/plugins/record/src/validation/private/validators.ts @@ -0,0 +1,48 @@ +import type { PayloadValidationFunction, WithSources } from '@xyo-network/payload-model' + +import type { DomainRegistration } from '../../DomainRegistration/index.ts' + +export const getDomainRegistrationReservedStringsValidator = ( + reservedStrings: string[], +): PayloadValidationFunction> => { + return (domainRegistration: WithSources) => { + const { domain } = domainRegistration + // Check if in one of the reserved name lists + if (reservedStrings.includes(domain)) { + console.log('Reserved name') + return false + } + return true + } +} + +export const getDomainRegistrationReservedFragmentsValidator = ( + reservedFragments: string[], +): PayloadValidationFunction> => { + return (domainRegistration: WithSources) => { + const { domain } = domainRegistration + // Check if any of our fragments are in the name + for (const reserved of reservedFragments) { + if (domain.includes(reserved)) { + console.log('Reserved name fragment') + return false + } + } + return true + } +} + +export const getDomainRegistrationReservedNamesValidator = (reservedNames: string[]): PayloadValidationFunction> => { + return (domainRegistration: WithSources) => { + const { domain } = domainRegistration + // Check if any of our fragments are in the name + for (const reserved of reservedNames) { + const parts = reserved.split(' ') + if (domain === [parts[1], parts[0]].join('') || domain === [parts[0], parts[1]].join('')) { + console.log('Reserved name') + return false + } + } + return true + } +} diff --git a/packages/payload/packages/xns/plugins/record/src/validation/public/index.ts b/packages/payload/packages/xns/plugins/record/src/validation/public/index.ts new file mode 100644 index 000000000..804263de1 --- /dev/null +++ b/packages/payload/packages/xns/plugins/record/src/validation/public/index.ts @@ -0,0 +1 @@ +export * from './validators.ts' diff --git a/packages/payload/packages/xns/plugins/record/src/validation/public/validators.ts b/packages/payload/packages/xns/plugins/record/src/validation/public/validators.ts new file mode 100644 index 000000000..0aa3735bb --- /dev/null +++ b/packages/payload/packages/xns/plugins/record/src/validation/public/validators.ts @@ -0,0 +1,77 @@ +import { isModuleName } from '@xyo-network/module-model' +import type { PayloadValidationFunction, WithSources } from '@xyo-network/payload-model' + +import type { DomainRegistration } from '../../DomainRegistration/index.ts' + +export const domainRegistrationCasingValidator: PayloadValidationFunction> = ( + domainRegistration: WithSources, +) => { + const { domain } = domainRegistration + // Check if all lowercase + if (domain.toLowerCase() !== domain) { + console.log('name must be lowercase') + return false + } + return true +} + +export const domainRegistrationModuleNameValidator: PayloadValidationFunction> = ( + domainRegistration: WithSources, +) => { + const { domain } = domainRegistration + + // check if domain is a valid name + if (!isModuleName(domain)) { + console.log(`Domain is not a valid module name: ${domain}`) + return false + } + + return true +} + +export const domainRegistrationTldValidator: PayloadValidationFunction> = ( + domainRegistration: WithSources, +) => { + const { tld } = domainRegistration + // Check if all lowercase + if (tld.toLowerCase() !== tld) { + console.log('TLD must be lowercase') + return false + } + // Check if supported TLDs + if (tld !== 'xyo') { + console.log('Only XYO TLD currently supported') + return false + } + return true +} + +export const getDomainRegistrationLengthValidator = (minNameLength: number): PayloadValidationFunction> => { + return (domainRegistration: WithSources) => { + const { domain } = domainRegistration + // Check if min length + if (domain.length < minNameLength) { + console.log(`name must be at least ${minNameLength} characters`) + return false + } + return true + } +} + +export const getDomainRegistrationAllowedHyphensValidator = ( + options?: { end?: boolean; start?: boolean }, +): PayloadValidationFunction> => { + return (domainRegistration: WithSources) => { + const { domain } = domainRegistration + const { start, end } = options ?? {} + if (!start && domain.startsWith('-')) { + console.log('name cannot start with hyphen') + return false + } + if (!end && domain.endsWith('-')) { + console.log('name cannot end with hyphen') + return false + } + return true + } +} diff --git a/packages/payload/packages/xns/plugins/record/src/validation/spec/tsconfig.json b/packages/payload/packages/xns/plugins/record/src/validation/spec/tsconfig.json new file mode 100644 index 000000000..e055e22d3 --- /dev/null +++ b/packages/payload/packages/xns/plugins/record/src/validation/spec/tsconfig.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "moduleResolution": "NodeNext", + "module": "NodeNext", + "sourceMap": true, + "inlineSources": true + }, + "extends": "@xylabs/tsconfig-jest" +} \ No newline at end of file diff --git a/packages/payload/packages/xns/plugins/record/src/validation/spec/validators.spec.ts b/packages/payload/packages/xns/plugins/record/src/validation/spec/validators.spec.ts new file mode 100644 index 000000000..85132888a --- /dev/null +++ b/packages/payload/packages/xns/plugins/record/src/validation/spec/validators.spec.ts @@ -0,0 +1,159 @@ +import type { WithSources } from '@xyo-network/payload-model' + +import type { DomainRegistration } from '../../DomainRegistration/index.ts' +import { DomainRegistrationSchema } from '../../DomainRegistration/index.ts' +import { + domainRegistrationCasingValidator, + domainRegistrationModuleNameValidator, + domainRegistrationTldValidator, + getDomainRegistrationAllowedHyphensValidator, + getDomainRegistrationLengthValidator, +} from '../public/index.ts' + +const baseDomainRegistrationFields: DomainRegistration = { + domain: '', + registrant: [], + registrar: [], + schema: DomainRegistrationSchema, + tld: 'xyo', +} + +describe('XNS Name Validators', () => { + describe('Public Validators', () => { + const cases = [ + { + name: 'domainRegistrationCasingValidator', + validator: domainRegistrationCasingValidator, + valid: ['example'], + invalid: ['Example'], + }, + { + name: 'domainRegistrationModuleNameValidator', + validator: domainRegistrationModuleNameValidator, + valid: ['valid-domain'], + invalid: ['invalid_domain'], + }, + ] + + describe.each(cases)('$name', ({ + validator, valid, invalid, + }) => { + describe('Valid', () => { + it.each(valid)('should return true for %s', (domain) => { + const domainRegistration: WithSources = { ...baseDomainRegistrationFields, domain } + expect(validator(domainRegistration)).toBe(true) + }) + }) + + describe('Invalid', () => { + it.each(invalid)('should return false for %s', (domain) => { + const domainRegistration: WithSources = { ...baseDomainRegistrationFields, domain } + expect(validator(domainRegistration)).toBe(false) + }) + }) + }) + + const casesTld = [ + { + name: 'domainRegistrationTldValidator', + valid: ['xyo'], + invalid: ['com', 'Xyo'], + }, + ] + + describe.each(casesTld)('$name', ({ valid, invalid }) => { + describe('Valid', () => { + it.each(valid)('should return true for %s', (tld) => { + const domainRegistration: WithSources = { ...baseDomainRegistrationFields, tld: tld as unknown as 'xyo' } + expect(domainRegistrationTldValidator(domainRegistration)).toBe(true) + }) + }) + + describe('Invalid', () => { + it.each(invalid)('should return false for %s', (tld) => { + const domainRegistration: WithSources = { ...baseDomainRegistrationFields, tld: tld as unknown as 'xyo' } + expect(domainRegistrationTldValidator(domainRegistration)).toBe(false) + }) + }) + }) + + const casesLength = [ + { + name: 'getDomainRegistrationLengthValidator', + minNameLength: 3, + valid: ['abc', 'abcd'], + invalid: ['', 'a'], + }, + ] + + describe.each(casesLength)('$name', ({ + minNameLength, valid, invalid, + }) => { + describe('Valid', () => { + it.each(valid)('should return true for %s', (domain) => { + const domainRegistration: WithSources = { ...baseDomainRegistrationFields, domain } + expect(getDomainRegistrationLengthValidator(minNameLength)(domainRegistration)).toBe(true) + }) + }) + + describe('Invalid', () => { + it.each(invalid)('should return false for %s', (domain) => { + const domainRegistration: WithSources = { ...baseDomainRegistrationFields, domain } + expect(getDomainRegistrationLengthValidator(minNameLength)(domainRegistration)).toBe(false) + }) + }) + }) + + const casesHyphens = [ + { + name: 'getDomainRegistrationAllowedHyphensValidator', + options: {}, + valid: ['example'], + invalid: ['example-', '-example', '-example-'], + }, + { + name: 'getDomainRegistrationAllowedHyphensValidator', + options: { start: true }, + valid: ['example', '-example'], + invalid: ['example-', '-example-'], + }, + { + name: 'getDomainRegistrationAllowedHyphensValidator', + options: { end: true }, + valid: ['example', 'example-'], + invalid: ['-example', '-example-'], + }, + { + name: 'getDomainRegistrationAllowedHyphensValidator', + options: { start: true, end: true }, + valid: ['example', '-example', 'example-', '-example-'], + invalid: [''], + }, + ] + + describe.each(casesHyphens)('$name with $options', ({ + options, valid, invalid, + }) => { + const validator = getDomainRegistrationAllowedHyphensValidator(options) + describe('Valid', () => { + it.each(valid)('should return true for %s', (domain) => { + const domainRegistration: WithSources = { ...baseDomainRegistrationFields, domain } + expect(validator(domainRegistration)).toBe(true) + }) + }) + + describe('Invalid', () => { + it.each(invalid)('should return false for %s', (domain) => { + if (domain) { + const domainRegistration: WithSources = { ...baseDomainRegistrationFields, domain } + expect(validator(domainRegistration)).toBe(false) + } else { + return true + } + }) + }) + }) + }) + // describe('Private Validators', () => { + // }) +}) From 9240459cea7fb8dce68909a5eb6fafb6bbefcf55 Mon Sep 17 00:00:00 2001 From: Matt Jones <885417+jonesmac@users.noreply.github.com> Date: Tue, 3 Sep 2024 17:54:49 -0400 Subject: [PATCH 02/46] move spec --- .../plugins/record/src/validation/{ => public}/spec/tsconfig.json | 0 .../record/src/validation/{ => public}/spec/validators.spec.ts | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename packages/payload/packages/xns/plugins/record/src/validation/{ => public}/spec/tsconfig.json (100%) rename packages/payload/packages/xns/plugins/record/src/validation/{ => public}/spec/validators.spec.ts (100%) diff --git a/packages/payload/packages/xns/plugins/record/src/validation/spec/tsconfig.json b/packages/payload/packages/xns/plugins/record/src/validation/public/spec/tsconfig.json similarity index 100% rename from packages/payload/packages/xns/plugins/record/src/validation/spec/tsconfig.json rename to packages/payload/packages/xns/plugins/record/src/validation/public/spec/tsconfig.json diff --git a/packages/payload/packages/xns/plugins/record/src/validation/spec/validators.spec.ts b/packages/payload/packages/xns/plugins/record/src/validation/public/spec/validators.spec.ts similarity index 100% rename from packages/payload/packages/xns/plugins/record/src/validation/spec/validators.spec.ts rename to packages/payload/packages/xns/plugins/record/src/validation/public/spec/validators.spec.ts From fd922dc6ced91cac24ef0f339ab83d050fd82750 Mon Sep 17 00:00:00 2001 From: Matt Jones <885417+jonesmac@users.noreply.github.com> Date: Tue, 3 Sep 2024 18:03:54 -0400 Subject: [PATCH 03/46] WIP - private validators --- .../src/validation/private/spec/tsconfig.json | 13 +++++ .../private/spec/validators.spec.ts | 55 +++++++++++++++++++ .../validation/public/spec/validators.spec.ts | 8 +-- 3 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 packages/payload/packages/xns/plugins/record/src/validation/private/spec/tsconfig.json create mode 100644 packages/payload/packages/xns/plugins/record/src/validation/private/spec/validators.spec.ts diff --git a/packages/payload/packages/xns/plugins/record/src/validation/private/spec/tsconfig.json b/packages/payload/packages/xns/plugins/record/src/validation/private/spec/tsconfig.json new file mode 100644 index 000000000..e055e22d3 --- /dev/null +++ b/packages/payload/packages/xns/plugins/record/src/validation/private/spec/tsconfig.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "moduleResolution": "NodeNext", + "module": "NodeNext", + "sourceMap": true, + "inlineSources": true + }, + "extends": "@xylabs/tsconfig-jest" +} \ No newline at end of file diff --git a/packages/payload/packages/xns/plugins/record/src/validation/private/spec/validators.spec.ts b/packages/payload/packages/xns/plugins/record/src/validation/private/spec/validators.spec.ts new file mode 100644 index 000000000..f0e25db9a --- /dev/null +++ b/packages/payload/packages/xns/plugins/record/src/validation/private/spec/validators.spec.ts @@ -0,0 +1,55 @@ +import type { WithSources } from '@xyo-network/payload-model' + +import type { DomainRegistration } from '../../../DomainRegistration/index.ts' +import { DomainRegistrationSchema } from '../../../DomainRegistration/index.ts' +import { getDomainRegistrationReservedStringsValidator } from '../index.ts' + +const baseDomainRegistrationFields: DomainRegistration = { + domain: '', + registrant: [], + registrar: [], + schema: DomainRegistrationSchema, + tld: 'xyo', +} + +describe('XNS Name Validators', () => { + describe('Private Validators', () => { + const cases = [ + { + name: 'ReservedStringsValidator', + reservedStrings: ['foo'], + valid: ['bar'], + invalid: ['foo'], + }, + { + name: 'ReservedStringsValidator', + reservedStrings: [], + valid: ['bar', 'foobar'], + invalid: [''], + }, + ] + + describe.each(cases)('$name', ({ + valid, invalid, reservedStrings, + }) => { + const validator = getDomainRegistrationReservedStringsValidator(reservedStrings) + describe('Valid', () => { + it.each(valid)('should return true for %s', (domain) => { + const domainRegistration: WithSources = { ...baseDomainRegistrationFields, domain } + expect(validator(domainRegistration)).toBe(true) + }) + }) + + describe('Invalid', () => { + it.each(invalid)('should return false for %s', (domain) => { + if (domain) { + const domainRegistration: WithSources = { ...baseDomainRegistrationFields, domain } + expect(validator(domainRegistration)).toBe(false) + } else { + expect(true).toBe(true) + } + }) + }) + }) + }) +}) diff --git a/packages/payload/packages/xns/plugins/record/src/validation/public/spec/validators.spec.ts b/packages/payload/packages/xns/plugins/record/src/validation/public/spec/validators.spec.ts index 85132888a..9222470fc 100644 --- a/packages/payload/packages/xns/plugins/record/src/validation/public/spec/validators.spec.ts +++ b/packages/payload/packages/xns/plugins/record/src/validation/public/spec/validators.spec.ts @@ -1,14 +1,14 @@ import type { WithSources } from '@xyo-network/payload-model' -import type { DomainRegistration } from '../../DomainRegistration/index.ts' -import { DomainRegistrationSchema } from '../../DomainRegistration/index.ts' +import type { DomainRegistration } from '../../../DomainRegistration/index.ts' +import { DomainRegistrationSchema } from '../../../DomainRegistration/index.ts' import { domainRegistrationCasingValidator, domainRegistrationModuleNameValidator, domainRegistrationTldValidator, getDomainRegistrationAllowedHyphensValidator, getDomainRegistrationLengthValidator, -} from '../public/index.ts' +} from '../index.ts' const baseDomainRegistrationFields: DomainRegistration = { domain: '', @@ -154,6 +154,4 @@ describe('XNS Name Validators', () => { }) }) }) - // describe('Private Validators', () => { - // }) }) From 9ab0088ba6a5350294c4201e12de53eaa8c2e066 Mon Sep 17 00:00:00 2001 From: Matt Jones <885417+jonesmac@users.noreply.github.com> Date: Tue, 3 Sep 2024 19:39:56 -0400 Subject: [PATCH 04/46] validate reserved fragments and names --- cspell.json | 2 + .../private/spec/validators.spec.ts | 42 ++++++++++++++++--- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/cspell.json b/cspell.json index 06288577e..2af5e6911 100644 --- a/cspell.json +++ b/cspell.json @@ -26,6 +26,7 @@ "decentralnetworkservices", "deregistering", "deregisters", + "doejohn", "dotenv", "emittery", "etherchain", @@ -47,6 +48,7 @@ "interoperably", "IPFS", "IXSCAN", + "johndoe", "jsdom", "jsonpatch", "keccak", diff --git a/packages/payload/packages/xns/plugins/record/src/validation/private/spec/validators.spec.ts b/packages/payload/packages/xns/plugins/record/src/validation/private/spec/validators.spec.ts index f0e25db9a..240f7b4e7 100644 --- a/packages/payload/packages/xns/plugins/record/src/validation/private/spec/validators.spec.ts +++ b/packages/payload/packages/xns/plugins/record/src/validation/private/spec/validators.spec.ts @@ -2,7 +2,9 @@ import type { WithSources } from '@xyo-network/payload-model' import type { DomainRegistration } from '../../../DomainRegistration/index.ts' import { DomainRegistrationSchema } from '../../../DomainRegistration/index.ts' -import { getDomainRegistrationReservedStringsValidator } from '../index.ts' +import { + getDomainRegistrationReservedFragmentsValidator, getDomainRegistrationReservedNamesValidator, getDomainRegistrationReservedStringsValidator, +} from '../index.ts' const baseDomainRegistrationFields: DomainRegistration = { domain: '', @@ -16,23 +18,53 @@ describe('XNS Name Validators', () => { describe('Private Validators', () => { const cases = [ { + getValidator: getDomainRegistrationReservedStringsValidator, name: 'ReservedStringsValidator', - reservedStrings: ['foo'], + reservedList: ['foo'], valid: ['bar'], invalid: ['foo'], }, { + getValidator: getDomainRegistrationReservedStringsValidator, name: 'ReservedStringsValidator', - reservedStrings: [], + reservedList: [], valid: ['bar', 'foobar'], invalid: [''], }, + { + getValidator: getDomainRegistrationReservedFragmentsValidator, + name: 'ReservedFragmentsValidator', + reservedList: ['foo'], + valid: ['bar'], + invalid: ['foobar', 'bar-foo'], + }, + { + getValidator: getDomainRegistrationReservedFragmentsValidator, + name: 'ReservedFragmentsValidator', + reservedList: [], + valid: ['foobar', 'bar-foo'], + invalid: [''], + }, + { + getValidator: getDomainRegistrationReservedNamesValidator, + name: 'ReservedNamesValidator', + reservedList: ['john doe'], + valid: ['john1'], + invalid: ['johndoe', 'doejohn'], + }, + { + getValidator: getDomainRegistrationReservedNamesValidator, + name: 'ReservedNamesValidator', + reservedList: [], + valid: ['john', 'doe'], + invalid: [''], + }, ] describe.each(cases)('$name', ({ - valid, invalid, reservedStrings, + getValidator, valid, invalid, reservedList, }) => { - const validator = getDomainRegistrationReservedStringsValidator(reservedStrings) + const validator = getValidator(reservedList) describe('Valid', () => { it.each(valid)('should return true for %s', (domain) => { const domainRegistration: WithSources = { ...baseDomainRegistrationFields, domain } From 0063c47c34996706fa17143c3146328303f5fddf Mon Sep 17 00:00:00 2001 From: Matt Jones <885417+jonesmac@users.noreply.github.com> Date: Tue, 3 Sep 2024 19:42:11 -0400 Subject: [PATCH 05/46] nest validation directory inside helpers directory --- .../payload/packages/xns/plugins/record/src/helpers/index.ts | 1 + .../packages/xns/plugins/record/src/helpers/validation/index.ts | 2 ++ .../record/src/{ => helpers}/validation/private/index.ts | 0 .../src/{ => helpers}/validation/private/spec/tsconfig.json | 0 .../{ => helpers}/validation/private/spec/validators.spec.ts | 0 .../record/src/{ => helpers}/validation/private/validators.ts | 0 .../plugins/record/src/{ => helpers}/validation/public/index.ts | 0 .../src/{ => helpers}/validation/public/spec/tsconfig.json | 0 .../src/{ => helpers}/validation/public/spec/validators.spec.ts | 0 .../record/src/{ => helpers}/validation/public/validators.ts | 0 packages/payload/packages/xns/plugins/record/src/index.ts | 1 + 11 files changed, 4 insertions(+) create mode 100644 packages/payload/packages/xns/plugins/record/src/helpers/index.ts create mode 100644 packages/payload/packages/xns/plugins/record/src/helpers/validation/index.ts rename packages/payload/packages/xns/plugins/record/src/{ => helpers}/validation/private/index.ts (100%) rename packages/payload/packages/xns/plugins/record/src/{ => helpers}/validation/private/spec/tsconfig.json (100%) rename packages/payload/packages/xns/plugins/record/src/{ => helpers}/validation/private/spec/validators.spec.ts (100%) rename packages/payload/packages/xns/plugins/record/src/{ => helpers}/validation/private/validators.ts (100%) rename packages/payload/packages/xns/plugins/record/src/{ => helpers}/validation/public/index.ts (100%) rename packages/payload/packages/xns/plugins/record/src/{ => helpers}/validation/public/spec/tsconfig.json (100%) rename packages/payload/packages/xns/plugins/record/src/{ => helpers}/validation/public/spec/validators.spec.ts (100%) rename packages/payload/packages/xns/plugins/record/src/{ => helpers}/validation/public/validators.ts (100%) diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/index.ts b/packages/payload/packages/xns/plugins/record/src/helpers/index.ts new file mode 100644 index 000000000..1ba6af44c --- /dev/null +++ b/packages/payload/packages/xns/plugins/record/src/helpers/index.ts @@ -0,0 +1 @@ +export * from './validation/index.ts' diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/validation/index.ts b/packages/payload/packages/xns/plugins/record/src/helpers/validation/index.ts new file mode 100644 index 000000000..0f6e88eee --- /dev/null +++ b/packages/payload/packages/xns/plugins/record/src/helpers/validation/index.ts @@ -0,0 +1,2 @@ +export * from './private/index.ts' +export * from './public/index.ts' diff --git a/packages/payload/packages/xns/plugins/record/src/validation/private/index.ts b/packages/payload/packages/xns/plugins/record/src/helpers/validation/private/index.ts similarity index 100% rename from packages/payload/packages/xns/plugins/record/src/validation/private/index.ts rename to packages/payload/packages/xns/plugins/record/src/helpers/validation/private/index.ts diff --git a/packages/payload/packages/xns/plugins/record/src/validation/private/spec/tsconfig.json b/packages/payload/packages/xns/plugins/record/src/helpers/validation/private/spec/tsconfig.json similarity index 100% rename from packages/payload/packages/xns/plugins/record/src/validation/private/spec/tsconfig.json rename to packages/payload/packages/xns/plugins/record/src/helpers/validation/private/spec/tsconfig.json diff --git a/packages/payload/packages/xns/plugins/record/src/validation/private/spec/validators.spec.ts b/packages/payload/packages/xns/plugins/record/src/helpers/validation/private/spec/validators.spec.ts similarity index 100% rename from packages/payload/packages/xns/plugins/record/src/validation/private/spec/validators.spec.ts rename to packages/payload/packages/xns/plugins/record/src/helpers/validation/private/spec/validators.spec.ts diff --git a/packages/payload/packages/xns/plugins/record/src/validation/private/validators.ts b/packages/payload/packages/xns/plugins/record/src/helpers/validation/private/validators.ts similarity index 100% rename from packages/payload/packages/xns/plugins/record/src/validation/private/validators.ts rename to packages/payload/packages/xns/plugins/record/src/helpers/validation/private/validators.ts diff --git a/packages/payload/packages/xns/plugins/record/src/validation/public/index.ts b/packages/payload/packages/xns/plugins/record/src/helpers/validation/public/index.ts similarity index 100% rename from packages/payload/packages/xns/plugins/record/src/validation/public/index.ts rename to packages/payload/packages/xns/plugins/record/src/helpers/validation/public/index.ts diff --git a/packages/payload/packages/xns/plugins/record/src/validation/public/spec/tsconfig.json b/packages/payload/packages/xns/plugins/record/src/helpers/validation/public/spec/tsconfig.json similarity index 100% rename from packages/payload/packages/xns/plugins/record/src/validation/public/spec/tsconfig.json rename to packages/payload/packages/xns/plugins/record/src/helpers/validation/public/spec/tsconfig.json diff --git a/packages/payload/packages/xns/plugins/record/src/validation/public/spec/validators.spec.ts b/packages/payload/packages/xns/plugins/record/src/helpers/validation/public/spec/validators.spec.ts similarity index 100% rename from packages/payload/packages/xns/plugins/record/src/validation/public/spec/validators.spec.ts rename to packages/payload/packages/xns/plugins/record/src/helpers/validation/public/spec/validators.spec.ts diff --git a/packages/payload/packages/xns/plugins/record/src/validation/public/validators.ts b/packages/payload/packages/xns/plugins/record/src/helpers/validation/public/validators.ts similarity index 100% rename from packages/payload/packages/xns/plugins/record/src/validation/public/validators.ts rename to packages/payload/packages/xns/plugins/record/src/helpers/validation/public/validators.ts diff --git a/packages/payload/packages/xns/plugins/record/src/index.ts b/packages/payload/packages/xns/plugins/record/src/index.ts index fbd41abe3..14eceafa0 100644 --- a/packages/payload/packages/xns/plugins/record/src/index.ts +++ b/packages/payload/packages/xns/plugins/record/src/index.ts @@ -6,3 +6,4 @@ export * from './DomainEstimate/index.ts' export * from './DomainRegistration/index.ts' export * from './Duration/index.ts' export * from './Hash/index.ts' +export * from './helpers/index.ts' From 57f3493fe175241b8cac18acbecafe1e6ae26663 Mon Sep 17 00:00:00 2001 From: Matt Jones <885417+jonesmac@users.noreply.github.com> Date: Tue, 3 Sep 2024 21:07:25 -0400 Subject: [PATCH 06/46] XnsNameHelper and specs --- .../packages/xns/plugins/record/package.json | 2 + .../plugins/record/src/helpers/name/Name.ts | 56 ++++++++++++ .../record/src/helpers/name/spec/Name.spec.ts | 85 +++++++++++++++++++ .../src/helpers/name/spec/tsconfig.json | 13 +++ yarn.lock | 16 ++-- 5 files changed, 165 insertions(+), 7 deletions(-) create mode 100644 packages/payload/packages/xns/plugins/record/src/helpers/name/Name.ts create mode 100644 packages/payload/packages/xns/plugins/record/src/helpers/name/spec/Name.spec.ts create mode 100644 packages/payload/packages/xns/plugins/record/src/helpers/name/spec/tsconfig.json diff --git a/packages/payload/packages/xns/plugins/record/package.json b/packages/payload/packages/xns/plugins/record/package.json index 6e006e748..92fce3500 100644 --- a/packages/payload/packages/xns/plugins/record/package.json +++ b/packages/payload/packages/xns/plugins/record/package.json @@ -29,8 +29,10 @@ "module": "dist/neutral/index.mjs", "types": "dist/neutral/index.d.ts", "dependencies": { + "@xylabs/assert": "4.0.9", "@xylabs/exists": "^4.0.9", "@xylabs/hex": "^4.0.9", + "@xylabs/promise": "^4.0.9", "@xyo-network/boundwitness-model": "^3.1.4", "@xyo-network/boundwitness-validator": "^3.1.4", "@xyo-network/module-model": "^3.1.4", diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/name/Name.ts b/packages/payload/packages/xns/plugins/record/src/helpers/name/Name.ts new file mode 100644 index 000000000..5e5c2311a --- /dev/null +++ b/packages/payload/packages/xns/plugins/record/src/helpers/name/Name.ts @@ -0,0 +1,56 @@ +import { assertEx } from '@xylabs/assert' +import { isHash } from '@xylabs/hex' +import type { Promisable } from '@xylabs/promise' +import { PayloadBuilder } from '@xyo-network/payload-builder' + +import type { DomainRegistration } from '../../DomainRegistration/index.ts' +import { DomainRegistrationSchema } from '../../DomainRegistration/index.ts' + +export type ValidSourceTypes = 'xnsName' | 'hash' | null + +export class XnsNameHelper { + static ValidTLDs = ['.xyo'] as const + + private _xnsName: DomainRegistration + + private constructor(xnsName: DomainRegistration) { + this._xnsName = xnsName + } + + get domain() { + return assertEx(this.xnsName.domain, () => 'domain not found in payload') + } + + get tld() { + return assertEx(this.xnsName.tld, () => 'tld not found in payload') + } + + get xnsName() { + return assertEx(this._xnsName, () => 'XnsNameHelper xnsName not set') + } + + static fromPayload(domainRegistration: DomainRegistration): Promisable { + return new XnsNameHelper(domainRegistration) + } + + static async fromString(xnsName: string) { + const parts = xnsName.split('.') + assertEx(parts.length === 2, () => 'Unable to parse xnsName') + + const domain = parts[0] + const tld = parts[1] as 'xyo' + const domainRegistration: DomainRegistration = { + schema: DomainRegistrationSchema, domain, tld, registrant: [], registrar: [], + } + const payload = await PayloadBuilder.build(domainRegistration) + + return new XnsNameHelper(payload) + } + + static isXnsNameOrHash(source?: string): ValidSourceTypes { + const xnsName = XnsNameHelper.ValidTLDs.some(tld => source?.endsWith(tld)) ? source : null + const hash = isHash(source) ? source : null + + return xnsName ? 'xnsName' : hash ? 'hash' : null + } +} diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/name/spec/Name.spec.ts b/packages/payload/packages/xns/plugins/record/src/helpers/name/spec/Name.spec.ts new file mode 100644 index 000000000..e4bc26490 --- /dev/null +++ b/packages/payload/packages/xns/plugins/record/src/helpers/name/spec/Name.spec.ts @@ -0,0 +1,85 @@ +import type { DomainRegistration } from '../../../DomainRegistration/index.ts' +import { DomainRegistrationSchema } from '../../../DomainRegistration/index.ts' +import { XnsNameHelper } from '../Name.ts' + +describe('XnsNameHelper', () => { + describe('domain getter', () => { + it('should return the domain if set', async () => { + const domainRegistration: DomainRegistration = { + schema: DomainRegistrationSchema, domain: 'example', tld: 'xyo', registrant: [], registrar: [], + } + const helper = await XnsNameHelper.fromPayload(domainRegistration) + expect(helper.domain).toBe('example') + }) + + it('should throw an error if domain is not set', async () => { + const domainRegistration: DomainRegistration = { + schema: DomainRegistrationSchema, domain: '', tld: 'xyo', registrant: [], registrar: [], + } + const helper = await XnsNameHelper.fromPayload(domainRegistration) + expect(() => helper.domain).toThrow('domain not found in payload') + }) + }) + + describe('tld getter', () => { + it('should return the tld if set', async () => { + const domainRegistration: DomainRegistration = { + schema: DomainRegistrationSchema, domain: 'example', tld: 'xyo', registrant: [], registrar: [], + } + const helper = await XnsNameHelper.fromPayload(domainRegistration) + expect(helper.tld).toBe('xyo') + }) + + it('should throw an error if tld is not set', async () => { + const domainRegistration: DomainRegistration = { + schema: DomainRegistrationSchema, domain: 'example', tld: '' as 'xyo', registrant: [], registrar: [], + } + const helper = await XnsNameHelper.fromPayload(domainRegistration) + expect(() => helper.tld).toThrow('tld not found in payload') + }) + }) + + describe('xnsName getter', () => { + it('should return the xnsName if set', async () => { + const domainRegistration: DomainRegistration = { + schema: DomainRegistrationSchema, domain: 'example', tld: 'xyo', registrant: [], registrar: [], + } + const helper = await XnsNameHelper.fromPayload(domainRegistration) + expect(helper.xnsName).toBe(domainRegistration) + }) + + it('should throw an error if xnsName is not set', async () => { + const helper = await XnsNameHelper.fromPayload(undefined as unknown as DomainRegistration) + expect(() => helper.xnsName).toThrow('XnsNameHelper xnsName not set') + }) + }) + + describe('fromString', () => { + it('should create an instance from a valid xnsName string', async () => { + const domainRegistration: DomainRegistration = { + schema: DomainRegistrationSchema, domain: 'example', tld: 'xyo', registrant: [], registrar: [], + } + const helper = await XnsNameHelper.fromString('example.xyo') + expect(helper.xnsName.domain).toBe(domainRegistration.domain) + expect(helper.xnsName.tld).toBe(domainRegistration.tld) + }) + + it('should throw an error if xnsName string is invalid', async () => { + await expect(XnsNameHelper.fromString('invalid')).rejects.toThrow('Unable to parse xnsName') + }) + }) + + describe('isXnsNameOrHash', () => { + it('should return "xnsName" if the source ends with a valid TLD', () => { + expect(XnsNameHelper.isXnsNameOrHash('example.xyo')).toBe('xnsName') + }) + + it('should return "hash" if the source is a valid hash', () => { + expect(XnsNameHelper.isXnsNameOrHash('c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2')).toBe('hash') + }) + + it('should return null if the source is neither a valid xnsName nor a hash', () => { + expect(XnsNameHelper.isXnsNameOrHash('invalid')).toBe(null) + }) + }) +}) diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/name/spec/tsconfig.json b/packages/payload/packages/xns/plugins/record/src/helpers/name/spec/tsconfig.json new file mode 100644 index 000000000..e055e22d3 --- /dev/null +++ b/packages/payload/packages/xns/plugins/record/src/helpers/name/spec/tsconfig.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "moduleResolution": "NodeNext", + "module": "NodeNext", + "sourceMap": true, + "inlineSources": true + }, + "extends": "@xylabs/tsconfig-jest" +} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index b9d01475c..1ecb57b2c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3819,6 +3819,13 @@ __metadata: languageName: node linkType: hard +"@xylabs/assert@npm:4.0.9, @xylabs/assert@npm:^4.0.5, @xylabs/assert@npm:^4.0.9": + version: 4.0.9 + resolution: "@xylabs/assert@npm:4.0.9" + checksum: 10/1287f1bab9fe1fd6580edd0ef2a8ea408928bf4540fb613e9a7f16e648c76256311104dda7b3cd032e888ba4992dfe66e95c4a9489f80fab1298dc0d0c137994 + languageName: node + linkType: hard + "@xylabs/assert@npm:^3.0.14": version: 3.6.12 resolution: "@xylabs/assert@npm:3.6.12" @@ -3826,13 +3833,6 @@ __metadata: languageName: node linkType: hard -"@xylabs/assert@npm:^4.0.5, @xylabs/assert@npm:^4.0.9": - version: 4.0.9 - resolution: "@xylabs/assert@npm:4.0.9" - checksum: 10/1287f1bab9fe1fd6580edd0ef2a8ea408928bf4540fb613e9a7f16e648c76256311104dda7b3cd032e888ba4992dfe66e95c4a9489f80fab1298dc0d0c137994 - languageName: node - linkType: hard - "@xylabs/axios@npm:^4.0.5, @xylabs/axios@npm:^4.0.9": version: 4.0.9 resolution: "@xylabs/axios@npm:4.0.9" @@ -7791,8 +7791,10 @@ __metadata: version: 0.0.0-use.local resolution: "@xyo-network/xns-record-payload-plugins@workspace:packages/payload/packages/xns/plugins/record" dependencies: + "@xylabs/assert": "npm:4.0.9" "@xylabs/exists": "npm:^4.0.9" "@xylabs/hex": "npm:^4.0.9" + "@xylabs/promise": "npm:^4.0.9" "@xylabs/ts-scripts-yarn3": "npm:^4.0.7" "@xylabs/tsconfig": "npm:^4.0.7" "@xyo-network/account": "npm:^3.1.4" From 5824b7e8654e2cbf4c985b782b1a113f4811d09d Mon Sep 17 00:00:00 2001 From: Matt Jones <885417+jonesmac@users.noreply.github.com> Date: Tue, 3 Sep 2024 21:11:25 -0400 Subject: [PATCH 07/46] fix import path --- .../plugins/record/src/helpers/validation/public/validators.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/validation/public/validators.ts b/packages/payload/packages/xns/plugins/record/src/helpers/validation/public/validators.ts index 0aa3735bb..42383ac1b 100644 --- a/packages/payload/packages/xns/plugins/record/src/helpers/validation/public/validators.ts +++ b/packages/payload/packages/xns/plugins/record/src/helpers/validation/public/validators.ts @@ -1,7 +1,7 @@ import { isModuleName } from '@xyo-network/module-model' import type { PayloadValidationFunction, WithSources } from '@xyo-network/payload-model' -import type { DomainRegistration } from '../../DomainRegistration/index.ts' +import type { DomainRegistration } from '../../../DomainRegistration/index.ts' export const domainRegistrationCasingValidator: PayloadValidationFunction> = ( domainRegistration: WithSources, From ac53519c3422b0ca17f53979963c57fb6b90e418 Mon Sep 17 00:00:00 2001 From: Matt Jones <885417+jonesmac@users.noreply.github.com> Date: Tue, 3 Sep 2024 21:15:20 -0400 Subject: [PATCH 08/46] default minLength to 3 --- .../plugins/record/src/helpers/validation/public/validators.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/validation/public/validators.ts b/packages/payload/packages/xns/plugins/record/src/helpers/validation/public/validators.ts index 42383ac1b..1c6030137 100644 --- a/packages/payload/packages/xns/plugins/record/src/helpers/validation/public/validators.ts +++ b/packages/payload/packages/xns/plugins/record/src/helpers/validation/public/validators.ts @@ -46,7 +46,7 @@ export const domainRegistrationTldValidator: PayloadValidationFunction> => { +export const getDomainRegistrationLengthValidator = (minNameLength = 3): PayloadValidationFunction> => { return (domainRegistration: WithSources) => { const { domain } = domainRegistration // Check if min length From 8f0203ff57047542e83fc7a85173cad91003e401 Mon Sep 17 00:00:00 2001 From: Matt Jones <885417+jonesmac@users.noreply.github.com> Date: Tue, 3 Sep 2024 21:15:29 -0400 Subject: [PATCH 09/46] export public validators --- .../record/src/helpers/validation/public/validators.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/validation/public/validators.ts b/packages/payload/packages/xns/plugins/record/src/helpers/validation/public/validators.ts index 1c6030137..9449bab7a 100644 --- a/packages/payload/packages/xns/plugins/record/src/helpers/validation/public/validators.ts +++ b/packages/payload/packages/xns/plugins/record/src/helpers/validation/public/validators.ts @@ -75,3 +75,11 @@ export const getDomainRegistrationAllowedHyphensValidator = ( return true } } + +export const XnsNamePublicValidators = [ + domainRegistrationCasingValidator, + domainRegistrationModuleNameValidator, + domainRegistrationTldValidator, + getDomainRegistrationLengthValidator(), + getDomainRegistrationAllowedHyphensValidator(), +] From b8520f4a30eb89bf5c7cfcf20615574d9d6a6782 Mon Sep 17 00:00:00 2001 From: Matt Jones <885417+jonesmac@users.noreply.github.com> Date: Tue, 3 Sep 2024 21:15:46 -0400 Subject: [PATCH 10/46] validate xns names and add tests --- .../xns/plugins/record/src/helpers/name/Name.ts | 5 +++++ .../record/src/helpers/name/spec/Name.spec.ts | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/name/Name.ts b/packages/payload/packages/xns/plugins/record/src/helpers/name/Name.ts index 5e5c2311a..030151867 100644 --- a/packages/payload/packages/xns/plugins/record/src/helpers/name/Name.ts +++ b/packages/payload/packages/xns/plugins/record/src/helpers/name/Name.ts @@ -5,6 +5,7 @@ import { PayloadBuilder } from '@xyo-network/payload-builder' import type { DomainRegistration } from '../../DomainRegistration/index.ts' import { DomainRegistrationSchema } from '../../DomainRegistration/index.ts' +import { XnsNamePublicValidators } from '../validation/index.ts' export type ValidSourceTypes = 'xnsName' | 'hash' | null @@ -47,6 +48,10 @@ export class XnsNameHelper { return new XnsNameHelper(payload) } + static isValid(domainRegistration: DomainRegistration) { + return XnsNamePublicValidators.every(validator => validator(domainRegistration)) + } + static isXnsNameOrHash(source?: string): ValidSourceTypes { const xnsName = XnsNameHelper.ValidTLDs.some(tld => source?.endsWith(tld)) ? source : null const hash = isHash(source) ? source : null diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/name/spec/Name.spec.ts b/packages/payload/packages/xns/plugins/record/src/helpers/name/spec/Name.spec.ts index e4bc26490..483af2c39 100644 --- a/packages/payload/packages/xns/plugins/record/src/helpers/name/spec/Name.spec.ts +++ b/packages/payload/packages/xns/plugins/record/src/helpers/name/spec/Name.spec.ts @@ -82,4 +82,20 @@ describe('XnsNameHelper', () => { expect(XnsNameHelper.isXnsNameOrHash('invalid')).toBe(null) }) }) + + describe('isValid', () => { + it('should return true for valid xns names', () => { + const domainRegistration: DomainRegistration = { + schema: DomainRegistrationSchema, domain: 'example', tld: 'xyo', registrant: [], registrar: [], + } + expect(XnsNameHelper.isValid(domainRegistration)).toBe(true) + }) + + it('should return false for invalid xns names', () => { + const domainRegistration: DomainRegistration = { + schema: DomainRegistrationSchema, domain: 'example-', tld: 'xyo', registrant: [], registrar: [], + } + expect(XnsNameHelper.isValid(domainRegistration)).toBe(false) + }) + }) }) From 7c91ef1da513b08009d42df89a6afecd14cc2ac0 Mon Sep 17 00:00:00 2001 From: Matt Jones <885417+jonesmac@users.noreply.github.com> Date: Wed, 4 Sep 2024 08:59:33 -0400 Subject: [PATCH 11/46] add mask method and rename method --- .../plugins/record/src/helpers/name/Name.ts | 36 ++++++++++++++++--- .../record/src/helpers/name/spec/Name.spec.ts | 6 ++-- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/name/Name.ts b/packages/payload/packages/xns/plugins/record/src/helpers/name/Name.ts index 030151867..60387313c 100644 --- a/packages/payload/packages/xns/plugins/record/src/helpers/name/Name.ts +++ b/packages/payload/packages/xns/plugins/record/src/helpers/name/Name.ts @@ -1,6 +1,7 @@ import { assertEx } from '@xylabs/assert' import { isHash } from '@xylabs/hex' import type { Promisable } from '@xylabs/promise' +import { DisallowedModuleIdentifierCharacters } from '@xyo-network/module-model' import { PayloadBuilder } from '@xyo-network/payload-builder' import type { DomainRegistration } from '../../DomainRegistration/index.ts' @@ -48,14 +49,41 @@ export class XnsNameHelper { return new XnsNameHelper(payload) } + /** + * Determine if a string is a valid XNS name or hash + * @param {string} source? + * @returns ValidSourceTypes + */ + static isPotentialXnsNameOrHash(source?: string): ValidSourceTypes { + const xnsName = XnsNameHelper.ValidTLDs.some(tld => source?.endsWith(tld)) ? source : null + const hash = isHash(source) ? source : null + + return xnsName ? 'xnsName' : hash ? 'hash' : null + } + static isValid(domainRegistration: DomainRegistration) { return XnsNamePublicValidators.every(validator => validator(domainRegistration)) } - static isXnsNameOrHash(source?: string): ValidSourceTypes { - const xnsName = XnsNameHelper.ValidTLDs.some(tld => source?.endsWith(tld)) ? source : null - const hash = isHash(source) ? source : null + /** + * Mask a string to be a valid XNS name + * @param {string} str + * @returns string + */ + static mask(str: string) { + // convert to lowercase + const lowercaseXnsName = str.toLowerCase() - return xnsName ? 'xnsName' : hash ? 'hash' : null + // remove everything except letters, numbers, and dashes + let formattedXnsName = lowercaseXnsName.replaceAll(/[^\dA-Za-z-]+$/g, '') + + // Filter out disallowed characters. + // NOTE: not necessary because of the previous formatting, but leaving for when certain special characters become allowed + for (const char of Object.keys(DisallowedModuleIdentifierCharacters)) { + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + formattedXnsName.includes(char) ? (formattedXnsName = formattedXnsName.replaceAll(char, '')) : formattedXnsName + } + + return formattedXnsName } } diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/name/spec/Name.spec.ts b/packages/payload/packages/xns/plugins/record/src/helpers/name/spec/Name.spec.ts index 483af2c39..afae52fb5 100644 --- a/packages/payload/packages/xns/plugins/record/src/helpers/name/spec/Name.spec.ts +++ b/packages/payload/packages/xns/plugins/record/src/helpers/name/spec/Name.spec.ts @@ -71,15 +71,15 @@ describe('XnsNameHelper', () => { describe('isXnsNameOrHash', () => { it('should return "xnsName" if the source ends with a valid TLD', () => { - expect(XnsNameHelper.isXnsNameOrHash('example.xyo')).toBe('xnsName') + expect(XnsNameHelper.isPotentialXnsNameOrHash('example.xyo')).toBe('xnsName') }) it('should return "hash" if the source is a valid hash', () => { - expect(XnsNameHelper.isXnsNameOrHash('c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2')).toBe('hash') + expect(XnsNameHelper.isPotentialXnsNameOrHash('c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2')).toBe('hash') }) it('should return null if the source is neither a valid xnsName nor a hash', () => { - expect(XnsNameHelper.isXnsNameOrHash('invalid')).toBe(null) + expect(XnsNameHelper.isPotentialXnsNameOrHash('invalid')).toBe(null) }) }) From 67e1d8c598fe0f72d7030fe8aa2e5cbc617c8249 Mon Sep 17 00:00:00 2001 From: Matt Jones <885417+jonesmac@users.noreply.github.com> Date: Wed, 4 Sep 2024 09:02:28 -0400 Subject: [PATCH 12/46] document XnsNameHelper methods --- .../xns/plugins/record/src/helpers/name/Name.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/name/Name.ts b/packages/payload/packages/xns/plugins/record/src/helpers/name/Name.ts index 60387313c..b26e2dd96 100644 --- a/packages/payload/packages/xns/plugins/record/src/helpers/name/Name.ts +++ b/packages/payload/packages/xns/plugins/record/src/helpers/name/Name.ts @@ -31,11 +31,21 @@ export class XnsNameHelper { return assertEx(this._xnsName, () => 'XnsNameHelper xnsName not set') } + /** + * Create an XnsNameHelper from a domain registration payload + * @param {DomainRegistration} domainRegistration + * @returns Promise + */ static fromPayload(domainRegistration: DomainRegistration): Promisable { return new XnsNameHelper(domainRegistration) } - static async fromString(xnsName: string) { + /** + * Create an XnsNameHelper from a string + * @param {string} xnsName + * @returns Promise + */ + static async fromString(xnsName: string): Promise { const parts = xnsName.split('.') assertEx(parts.length === 2, () => 'Unable to parse xnsName') From fc88af79c3b37e9f901d2295cdff49b1dccc53ef Mon Sep 17 00:00:00 2001 From: Matt Jones <885417+jonesmac@users.noreply.github.com> Date: Wed, 4 Sep 2024 09:02:53 -0400 Subject: [PATCH 13/46] fix import path --- .../plugins/record/src/helpers/validation/private/validators.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/validation/private/validators.ts b/packages/payload/packages/xns/plugins/record/src/helpers/validation/private/validators.ts index 7ffb10691..3e7147f06 100644 --- a/packages/payload/packages/xns/plugins/record/src/helpers/validation/private/validators.ts +++ b/packages/payload/packages/xns/plugins/record/src/helpers/validation/private/validators.ts @@ -1,6 +1,6 @@ import type { PayloadValidationFunction, WithSources } from '@xyo-network/payload-model' -import type { DomainRegistration } from '../../DomainRegistration/index.ts' +import type { DomainRegistration } from '../../../DomainRegistration/index.ts' export const getDomainRegistrationReservedStringsValidator = ( reservedStrings: string[], From bfdb442e876b79831359ed3970adf90820cf10f3 Mon Sep 17 00:00:00 2001 From: Matt Jones <885417+jonesmac@users.noreply.github.com> Date: Wed, 4 Sep 2024 09:17:39 -0400 Subject: [PATCH 14/46] fix import paths --- .../src/helpers/validation/private/spec/validators.spec.ts | 4 ++-- .../src/helpers/validation/public/spec/validators.spec.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/validation/private/spec/validators.spec.ts b/packages/payload/packages/xns/plugins/record/src/helpers/validation/private/spec/validators.spec.ts index 240f7b4e7..507d85b35 100644 --- a/packages/payload/packages/xns/plugins/record/src/helpers/validation/private/spec/validators.spec.ts +++ b/packages/payload/packages/xns/plugins/record/src/helpers/validation/private/spec/validators.spec.ts @@ -1,7 +1,7 @@ import type { WithSources } from '@xyo-network/payload-model' -import type { DomainRegistration } from '../../../DomainRegistration/index.ts' -import { DomainRegistrationSchema } from '../../../DomainRegistration/index.ts' +import type { DomainRegistration } from '../../../../DomainRegistration/index.ts' +import { DomainRegistrationSchema } from '../../../../DomainRegistration/index.ts' import { getDomainRegistrationReservedFragmentsValidator, getDomainRegistrationReservedNamesValidator, getDomainRegistrationReservedStringsValidator, } from '../index.ts' diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/validation/public/spec/validators.spec.ts b/packages/payload/packages/xns/plugins/record/src/helpers/validation/public/spec/validators.spec.ts index 9222470fc..f19f17307 100644 --- a/packages/payload/packages/xns/plugins/record/src/helpers/validation/public/spec/validators.spec.ts +++ b/packages/payload/packages/xns/plugins/record/src/helpers/validation/public/spec/validators.spec.ts @@ -1,7 +1,7 @@ import type { WithSources } from '@xyo-network/payload-model' -import type { DomainRegistration } from '../../../DomainRegistration/index.ts' -import { DomainRegistrationSchema } from '../../../DomainRegistration/index.ts' +import type { DomainRegistration } from '../../../../DomainRegistration/index.ts' +import { DomainRegistrationSchema } from '../../../../DomainRegistration/index.ts' import { domainRegistrationCasingValidator, domainRegistrationModuleNameValidator, From 380a69a5f473c09fbdf3a0b9e87a82173ff66d6b Mon Sep 17 00:00:00 2001 From: Matt Jones <885417+jonesmac@users.noreply.github.com> Date: Wed, 4 Sep 2024 09:18:03 -0400 Subject: [PATCH 15/46] mask starting and ending hyphens and add specs --- .../plugins/record/src/helpers/name/Name.ts | 5 +++- .../record/src/helpers/name/spec/Name.spec.ts | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/name/Name.ts b/packages/payload/packages/xns/plugins/record/src/helpers/name/Name.ts index b26e2dd96..af6475e4a 100644 --- a/packages/payload/packages/xns/plugins/record/src/helpers/name/Name.ts +++ b/packages/payload/packages/xns/plugins/record/src/helpers/name/Name.ts @@ -87,8 +87,11 @@ export class XnsNameHelper { // remove everything except letters, numbers, and dashes let formattedXnsName = lowercaseXnsName.replaceAll(/[^\dA-Za-z-]+$/g, '') + // remove leading and trailing dashes + formattedXnsName = formattedXnsName.replaceAll(/^-+|-+$/g, '') + // Filter out disallowed characters. - // NOTE: not necessary because of the previous formatting, but leaving for when certain special characters become allowed + // NOTE: not necessary because of the regex/replacement above, but leaving for when certain special characters become allowed for (const char of Object.keys(DisallowedModuleIdentifierCharacters)) { // eslint-disable-next-line @typescript-eslint/no-unused-expressions formattedXnsName.includes(char) ? (formattedXnsName = formattedXnsName.replaceAll(char, '')) : formattedXnsName diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/name/spec/Name.spec.ts b/packages/payload/packages/xns/plugins/record/src/helpers/name/spec/Name.spec.ts index afae52fb5..0801c1161 100644 --- a/packages/payload/packages/xns/plugins/record/src/helpers/name/spec/Name.spec.ts +++ b/packages/payload/packages/xns/plugins/record/src/helpers/name/spec/Name.spec.ts @@ -98,4 +98,28 @@ describe('XnsNameHelper', () => { expect(XnsNameHelper.isValid(domainRegistration)).toBe(false) }) }) + + describe('mask', () => { + const cases = [ + ['Example$123', 'example123'], + ['Example/123', 'example123'], + ['Example.123', 'example123'], + ['Example-123', 'example-123'], + ['Example 123', 'example123'], + ['Example_123', 'example123'], + ['-Example_123-', 'example123'], + ['-Example_123', 'example123'], + ['Example_123-', 'example123'], + ['--Example_123', 'example123'], + ['Example_123--', 'example123'], + ['--Example_123--', 'example123'], + ['- Example_123 -', 'example123'], + ] + + describe.each(cases)('mask(%s)', (input, expected) => { + it(`should return ${expected}`, () => { + expect(XnsNameHelper.mask(input)).toBe(expected) + }) + }) + }) }) From db39b8489388f77ec99764f209b6eb2b635a8da2 Mon Sep 17 00:00:00 2001 From: Matt Jones <885417+jonesmac@users.noreply.github.com> Date: Wed, 4 Sep 2024 09:23:18 -0400 Subject: [PATCH 16/46] clean dep check --- packages/payload/packages/xns/plugins/record/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/payload/packages/xns/plugins/record/package.json b/packages/payload/packages/xns/plugins/record/package.json index 92fce3500..767e01faa 100644 --- a/packages/payload/packages/xns/plugins/record/package.json +++ b/packages/payload/packages/xns/plugins/record/package.json @@ -35,6 +35,7 @@ "@xylabs/promise": "^4.0.9", "@xyo-network/boundwitness-model": "^3.1.4", "@xyo-network/boundwitness-validator": "^3.1.4", + "@xyo-network/diviner-hash-lease": "^3.1.4", "@xyo-network/module-model": "^3.1.4", "@xyo-network/payload-builder": "^3.1.4", "@xyo-network/payload-model": "^3.1.4", @@ -45,7 +46,6 @@ "@xylabs/tsconfig": "^4.0.7", "@xyo-network/account": "^3.1.4", "@xyo-network/boundwitness-builder": "^3.1.4", - "@xyo-network/diviner-hash-lease": "^3.1.4", "typescript": "^5.5.4" }, "publishConfig": { From 4a5cca5f67be74423690f2dd6bb8088063620ba5 Mon Sep 17 00:00:00 2001 From: Matt Jones <885417+jonesmac@users.noreply.github.com> Date: Wed, 4 Sep 2024 09:29:11 -0400 Subject: [PATCH 17/46] doc comments to explain public vs private validators --- .../record/src/helpers/validation/private/validators.ts | 4 ++++ .../src/helpers/validation/public/spec/validators.spec.ts | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/validation/private/validators.ts b/packages/payload/packages/xns/plugins/record/src/helpers/validation/private/validators.ts index 3e7147f06..9b83d83d9 100644 --- a/packages/payload/packages/xns/plugins/record/src/helpers/validation/private/validators.ts +++ b/packages/payload/packages/xns/plugins/record/src/helpers/validation/private/validators.ts @@ -1,3 +1,7 @@ +/** + * NOTE: These validators are private because they rely on private data that cannot be shared with clients. + */ + import type { PayloadValidationFunction, WithSources } from '@xyo-network/payload-model' import type { DomainRegistration } from '../../../DomainRegistration/index.ts' diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/validation/public/spec/validators.spec.ts b/packages/payload/packages/xns/plugins/record/src/helpers/validation/public/spec/validators.spec.ts index f19f17307..938a28308 100644 --- a/packages/payload/packages/xns/plugins/record/src/helpers/validation/public/spec/validators.spec.ts +++ b/packages/payload/packages/xns/plugins/record/src/helpers/validation/public/spec/validators.spec.ts @@ -1,3 +1,8 @@ +/** + * NOTE: These validators are public because they can be validated by clients + * and require no special access to private data. + */ + import type { WithSources } from '@xyo-network/payload-model' import type { DomainRegistration } from '../../../../DomainRegistration/index.ts' From 1bd85f37f2cafe8ce9f0234abc34c3b79727dda6 Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Wed, 4 Sep 2024 09:07:05 -0500 Subject: [PATCH 18/46] Simplify ternary --- .../packages/xns/plugins/record/src/helpers/name/Name.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/name/Name.ts b/packages/payload/packages/xns/plugins/record/src/helpers/name/Name.ts index af6475e4a..f623f74ae 100644 --- a/packages/payload/packages/xns/plugins/record/src/helpers/name/Name.ts +++ b/packages/payload/packages/xns/plugins/record/src/helpers/name/Name.ts @@ -65,10 +65,9 @@ export class XnsNameHelper { * @returns ValidSourceTypes */ static isPotentialXnsNameOrHash(source?: string): ValidSourceTypes { + if (isHash(source)) return 'hash' const xnsName = XnsNameHelper.ValidTLDs.some(tld => source?.endsWith(tld)) ? source : null - const hash = isHash(source) ? source : null - - return xnsName ? 'xnsName' : hash ? 'hash' : null + return xnsName ? 'xnsName' : null } static isValid(domainRegistration: DomainRegistration) { From 0a2f87b3f68c61595c60cfd55fa5d99fd93c6397 Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Wed, 4 Sep 2024 09:10:48 -0500 Subject: [PATCH 19/46] Use `replaceAll` idempotence to optimize performance --- .../packages/xns/plugins/record/src/helpers/name/Name.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/name/Name.ts b/packages/payload/packages/xns/plugins/record/src/helpers/name/Name.ts index f623f74ae..9dc696ba7 100644 --- a/packages/payload/packages/xns/plugins/record/src/helpers/name/Name.ts +++ b/packages/payload/packages/xns/plugins/record/src/helpers/name/Name.ts @@ -91,9 +91,8 @@ export class XnsNameHelper { // Filter out disallowed characters. // NOTE: not necessary because of the regex/replacement above, but leaving for when certain special characters become allowed - for (const char of Object.keys(DisallowedModuleIdentifierCharacters)) { - // eslint-disable-next-line @typescript-eslint/no-unused-expressions - formattedXnsName.includes(char) ? (formattedXnsName = formattedXnsName.replaceAll(char, '')) : formattedXnsName + for (const c of Object.keys(DisallowedModuleIdentifierCharacters)) { + formattedXnsName = formattedXnsName.replaceAll(c, '') } return formattedXnsName From 78e91018f7eb74c694d7ef57d87b54c463c016ee Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Wed, 4 Sep 2024 09:20:43 -0500 Subject: [PATCH 20/46] Optimize for loop with single pass regex --- .../plugins/record/src/helpers/name/Name.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/name/Name.ts b/packages/payload/packages/xns/plugins/record/src/helpers/name/Name.ts index 9dc696ba7..a093c7593 100644 --- a/packages/payload/packages/xns/plugins/record/src/helpers/name/Name.ts +++ b/packages/payload/packages/xns/plugins/record/src/helpers/name/Name.ts @@ -10,6 +10,16 @@ import { XnsNamePublicValidators } from '../validation/index.ts' export type ValidSourceTypes = 'xnsName' | 'hash' | null +// Escaping special regex characters in the disallowed keys +const escapeRegex = (str: string) => str.replaceAll(/[$()*+.?[\\\]^{|}]/g, String.raw`\$&`) + +// Escaping and then creating the regex +const disallowedCharsPattern = Object.keys(DisallowedModuleIdentifierCharacters) + .map(escapeRegex) + .join('') +// Creating the final regex +const REMOVE_DISALLOWED_CHARS = new RegExp(`[${disallowedCharsPattern}]`, 'g') + export class XnsNameHelper { static ValidTLDs = ['.xyo'] as const @@ -83,17 +93,15 @@ export class XnsNameHelper { // convert to lowercase const lowercaseXnsName = str.toLowerCase() - // remove everything except letters, numbers, and dashes + // Remove everything except letters, numbers, and dashes let formattedXnsName = lowercaseXnsName.replaceAll(/[^\dA-Za-z-]+$/g, '') - // remove leading and trailing dashes + // Remove leading and trailing dashes formattedXnsName = formattedXnsName.replaceAll(/^-+|-+$/g, '') // Filter out disallowed characters. // NOTE: not necessary because of the regex/replacement above, but leaving for when certain special characters become allowed - for (const c of Object.keys(DisallowedModuleIdentifierCharacters)) { - formattedXnsName = formattedXnsName.replaceAll(c, '') - } + formattedXnsName = formattedXnsName.replaceAll(REMOVE_DISALLOWED_CHARS, '') return formattedXnsName } From ff9e2412f5b22ce7ba62691f1270054db8459b13 Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Wed, 4 Sep 2024 09:29:15 -0500 Subject: [PATCH 21/46] Operate on domains --- .../plugins/record/src/helpers/name/Name.ts | 33 +++++------ .../record/src/helpers/name/spec/Name.spec.ts | 58 +++++++++---------- .../helpers/validation/public/validators.ts | 22 +++---- 3 files changed, 56 insertions(+), 57 deletions(-) diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/name/Name.ts b/packages/payload/packages/xns/plugins/record/src/helpers/name/Name.ts index a093c7593..14613c5b4 100644 --- a/packages/payload/packages/xns/plugins/record/src/helpers/name/Name.ts +++ b/packages/payload/packages/xns/plugins/record/src/helpers/name/Name.ts @@ -2,10 +2,12 @@ import { assertEx } from '@xylabs/assert' import { isHash } from '@xylabs/hex' import type { Promisable } from '@xylabs/promise' import { DisallowedModuleIdentifierCharacters } from '@xyo-network/module-model' -import { PayloadBuilder } from '@xyo-network/payload-builder' -import type { DomainRegistration } from '../../DomainRegistration/index.ts' -import { DomainRegistrationSchema } from '../../DomainRegistration/index.ts' +import type { + Domain, + TopLevelDomain, +} from '../../Domain/index.ts' +import { DomainSchema } from '../../Domain/index.ts' import { XnsNamePublicValidators } from '../validation/index.ts' export type ValidSourceTypes = 'xnsName' | 'hash' | null @@ -23,9 +25,9 @@ const REMOVE_DISALLOWED_CHARS = new RegExp(`[${disallowedCharsPattern}]`, 'g') export class XnsNameHelper { static ValidTLDs = ['.xyo'] as const - private _xnsName: DomainRegistration + private _xnsName: Domain - private constructor(xnsName: DomainRegistration) { + private constructor(xnsName: Domain) { this._xnsName = xnsName } @@ -43,11 +45,11 @@ export class XnsNameHelper { /** * Create an XnsNameHelper from a domain registration payload - * @param {DomainRegistration} domainRegistration + * @param {Domain} domain * @returns Promise */ - static fromPayload(domainRegistration: DomainRegistration): Promisable { - return new XnsNameHelper(domainRegistration) + static fromPayload(domain: Domain): Promisable { + return new XnsNameHelper(domain) } /** @@ -55,18 +57,15 @@ export class XnsNameHelper { * @param {string} xnsName * @returns Promise */ - static async fromString(xnsName: string): Promise { + static fromString(xnsName: string): XnsNameHelper { const parts = xnsName.split('.') assertEx(parts.length === 2, () => 'Unable to parse xnsName') const domain = parts[0] - const tld = parts[1] as 'xyo' - const domainRegistration: DomainRegistration = { - schema: DomainRegistrationSchema, domain, tld, registrant: [], registrar: [], - } - const payload = await PayloadBuilder.build(domainRegistration) - - return new XnsNameHelper(payload) + const tld = parts[1] as TopLevelDomain + return new XnsNameHelper({ + schema: DomainSchema, domain, tld, + }) } /** @@ -80,7 +79,7 @@ export class XnsNameHelper { return xnsName ? 'xnsName' : null } - static isValid(domainRegistration: DomainRegistration) { + static isValid(domainRegistration: Domain) { return XnsNamePublicValidators.every(validator => validator(domainRegistration)) } diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/name/spec/Name.spec.ts b/packages/payload/packages/xns/plugins/record/src/helpers/name/spec/Name.spec.ts index 0801c1161..38c52b34d 100644 --- a/packages/payload/packages/xns/plugins/record/src/helpers/name/spec/Name.spec.ts +++ b/packages/payload/packages/xns/plugins/record/src/helpers/name/spec/Name.spec.ts @@ -1,67 +1,67 @@ -import type { DomainRegistration } from '../../../DomainRegistration/index.ts' -import { DomainRegistrationSchema } from '../../../DomainRegistration/index.ts' +import type { Domain } from '../../../Domain/index.ts' +import { DomainSchema } from '../../../Domain/index.ts' import { XnsNameHelper } from '../Name.ts' describe('XnsNameHelper', () => { describe('domain getter', () => { it('should return the domain if set', async () => { - const domainRegistration: DomainRegistration = { - schema: DomainRegistrationSchema, domain: 'example', tld: 'xyo', registrant: [], registrar: [], + const domain: Domain = { + schema: DomainSchema, domain: 'example', tld: 'xyo', } - const helper = await XnsNameHelper.fromPayload(domainRegistration) + const helper = await XnsNameHelper.fromPayload(domain) expect(helper.domain).toBe('example') }) it('should throw an error if domain is not set', async () => { - const domainRegistration: DomainRegistration = { - schema: DomainRegistrationSchema, domain: '', tld: 'xyo', registrant: [], registrar: [], + const domain: Domain = { + schema: DomainSchema, domain: '', tld: 'xyo', } - const helper = await XnsNameHelper.fromPayload(domainRegistration) + const helper = await XnsNameHelper.fromPayload(domain) expect(() => helper.domain).toThrow('domain not found in payload') }) }) describe('tld getter', () => { it('should return the tld if set', async () => { - const domainRegistration: DomainRegistration = { - schema: DomainRegistrationSchema, domain: 'example', tld: 'xyo', registrant: [], registrar: [], + const domain: Domain = { + schema: DomainSchema, domain: 'example', tld: 'xyo', } - const helper = await XnsNameHelper.fromPayload(domainRegistration) + const helper = await XnsNameHelper.fromPayload(domain) expect(helper.tld).toBe('xyo') }) it('should throw an error if tld is not set', async () => { - const domainRegistration: DomainRegistration = { - schema: DomainRegistrationSchema, domain: 'example', tld: '' as 'xyo', registrant: [], registrar: [], + const domain: Domain = { + schema: DomainSchema, domain: 'example', tld: '' as 'xyo', } - const helper = await XnsNameHelper.fromPayload(domainRegistration) + const helper = await XnsNameHelper.fromPayload(domain) expect(() => helper.tld).toThrow('tld not found in payload') }) }) describe('xnsName getter', () => { it('should return the xnsName if set', async () => { - const domainRegistration: DomainRegistration = { - schema: DomainRegistrationSchema, domain: 'example', tld: 'xyo', registrant: [], registrar: [], + const domain: Domain = { + schema: DomainSchema, domain: 'example', tld: 'xyo', } - const helper = await XnsNameHelper.fromPayload(domainRegistration) - expect(helper.xnsName).toBe(domainRegistration) + const helper = await XnsNameHelper.fromPayload(domain) + expect(helper.xnsName).toBe(domain) }) it('should throw an error if xnsName is not set', async () => { - const helper = await XnsNameHelper.fromPayload(undefined as unknown as DomainRegistration) + const helper = await XnsNameHelper.fromPayload(undefined as unknown as Domain) expect(() => helper.xnsName).toThrow('XnsNameHelper xnsName not set') }) }) describe('fromString', () => { it('should create an instance from a valid xnsName string', async () => { - const domainRegistration: DomainRegistration = { - schema: DomainRegistrationSchema, domain: 'example', tld: 'xyo', registrant: [], registrar: [], + const domain: Domain = { + schema: DomainSchema, domain: 'example', tld: 'xyo', } const helper = await XnsNameHelper.fromString('example.xyo') - expect(helper.xnsName.domain).toBe(domainRegistration.domain) - expect(helper.xnsName.tld).toBe(domainRegistration.tld) + expect(helper.xnsName.domain).toBe(domain.domain) + expect(helper.xnsName.tld).toBe(domain.tld) }) it('should throw an error if xnsName string is invalid', async () => { @@ -85,17 +85,17 @@ describe('XnsNameHelper', () => { describe('isValid', () => { it('should return true for valid xns names', () => { - const domainRegistration: DomainRegistration = { - schema: DomainRegistrationSchema, domain: 'example', tld: 'xyo', registrant: [], registrar: [], + const domain: Domain = { + schema: DomainSchema, domain: 'example', tld: 'xyo', } - expect(XnsNameHelper.isValid(domainRegistration)).toBe(true) + expect(XnsNameHelper.isValid(domain)).toBe(true) }) it('should return false for invalid xns names', () => { - const domainRegistration: DomainRegistration = { - schema: DomainRegistrationSchema, domain: 'example-', tld: 'xyo', registrant: [], registrar: [], + const domain: Domain = { + schema: DomainSchema, domain: 'example-', tld: 'xyo', } - expect(XnsNameHelper.isValid(domainRegistration)).toBe(false) + expect(XnsNameHelper.isValid(domain)).toBe(false) }) }) diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/validation/public/validators.ts b/packages/payload/packages/xns/plugins/record/src/helpers/validation/public/validators.ts index 9449bab7a..c2c54f300 100644 --- a/packages/payload/packages/xns/plugins/record/src/helpers/validation/public/validators.ts +++ b/packages/payload/packages/xns/plugins/record/src/helpers/validation/public/validators.ts @@ -1,10 +1,10 @@ import { isModuleName } from '@xyo-network/module-model' import type { PayloadValidationFunction, WithSources } from '@xyo-network/payload-model' -import type { DomainRegistration } from '../../../DomainRegistration/index.ts' +import type { Domain } from '../../../Domain/index.ts' -export const domainRegistrationCasingValidator: PayloadValidationFunction> = ( - domainRegistration: WithSources, +export const domainRegistrationCasingValidator: PayloadValidationFunction> = ( + domainRegistration: WithSources, ) => { const { domain } = domainRegistration // Check if all lowercase @@ -15,8 +15,8 @@ export const domainRegistrationCasingValidator: PayloadValidationFunction> = ( - domainRegistration: WithSources, +export const domainRegistrationModuleNameValidator: PayloadValidationFunction> = ( + domainRegistration: WithSources, ) => { const { domain } = domainRegistration @@ -29,8 +29,8 @@ export const domainRegistrationModuleNameValidator: PayloadValidationFunction> = ( - domainRegistration: WithSources, +export const domainRegistrationTldValidator: PayloadValidationFunction> = ( + domainRegistration: WithSources, ) => { const { tld } = domainRegistration // Check if all lowercase @@ -46,8 +46,8 @@ export const domainRegistrationTldValidator: PayloadValidationFunction> => { - return (domainRegistration: WithSources) => { +export const getDomainRegistrationLengthValidator = (minNameLength = 3): PayloadValidationFunction> => { + return (domainRegistration: WithSources) => { const { domain } = domainRegistration // Check if min length if (domain.length < minNameLength) { @@ -60,8 +60,8 @@ export const getDomainRegistrationLengthValidator = (minNameLength = 3): Payload export const getDomainRegistrationAllowedHyphensValidator = ( options?: { end?: boolean; start?: boolean }, -): PayloadValidationFunction> => { - return (domainRegistration: WithSources) => { +): PayloadValidationFunction> => { + return (domainRegistration: WithSources) => { const { domain } = domainRegistration const { start, end } = options ?? {} if (!start && domain.startsWith('-')) { From a740a8d5174373813664ff36747a8c29d57dadfc Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Wed, 4 Sep 2024 09:53:13 -0500 Subject: [PATCH 22/46] Rename folders --- .../src/helpers/validation/{private => factory}/index.ts | 0 .../validation/{private => factory}/spec/tsconfig.json | 0 .../validation/{private => factory}/spec/validators.spec.ts | 0 .../src/helpers/validation/{private => factory}/validators.ts | 0 .../xns/plugins/record/src/helpers/validation/index.ts | 4 ++-- .../src/helpers/validation/{public => validators}/index.ts | 0 .../validation/{public => validators}/spec/tsconfig.json | 0 .../validation/{public => validators}/spec/validators.spec.ts | 0 .../helpers/validation/{public => validators}/validators.ts | 0 9 files changed, 2 insertions(+), 2 deletions(-) rename packages/payload/packages/xns/plugins/record/src/helpers/validation/{private => factory}/index.ts (100%) rename packages/payload/packages/xns/plugins/record/src/helpers/validation/{private => factory}/spec/tsconfig.json (100%) rename packages/payload/packages/xns/plugins/record/src/helpers/validation/{private => factory}/spec/validators.spec.ts (100%) rename packages/payload/packages/xns/plugins/record/src/helpers/validation/{private => factory}/validators.ts (100%) rename packages/payload/packages/xns/plugins/record/src/helpers/validation/{public => validators}/index.ts (100%) rename packages/payload/packages/xns/plugins/record/src/helpers/validation/{public => validators}/spec/tsconfig.json (100%) rename packages/payload/packages/xns/plugins/record/src/helpers/validation/{public => validators}/spec/validators.spec.ts (100%) rename packages/payload/packages/xns/plugins/record/src/helpers/validation/{public => validators}/validators.ts (100%) diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/validation/private/index.ts b/packages/payload/packages/xns/plugins/record/src/helpers/validation/factory/index.ts similarity index 100% rename from packages/payload/packages/xns/plugins/record/src/helpers/validation/private/index.ts rename to packages/payload/packages/xns/plugins/record/src/helpers/validation/factory/index.ts diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/validation/private/spec/tsconfig.json b/packages/payload/packages/xns/plugins/record/src/helpers/validation/factory/spec/tsconfig.json similarity index 100% rename from packages/payload/packages/xns/plugins/record/src/helpers/validation/private/spec/tsconfig.json rename to packages/payload/packages/xns/plugins/record/src/helpers/validation/factory/spec/tsconfig.json diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/validation/private/spec/validators.spec.ts b/packages/payload/packages/xns/plugins/record/src/helpers/validation/factory/spec/validators.spec.ts similarity index 100% rename from packages/payload/packages/xns/plugins/record/src/helpers/validation/private/spec/validators.spec.ts rename to packages/payload/packages/xns/plugins/record/src/helpers/validation/factory/spec/validators.spec.ts diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/validation/private/validators.ts b/packages/payload/packages/xns/plugins/record/src/helpers/validation/factory/validators.ts similarity index 100% rename from packages/payload/packages/xns/plugins/record/src/helpers/validation/private/validators.ts rename to packages/payload/packages/xns/plugins/record/src/helpers/validation/factory/validators.ts diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/validation/index.ts b/packages/payload/packages/xns/plugins/record/src/helpers/validation/index.ts index 0f6e88eee..c5e28003f 100644 --- a/packages/payload/packages/xns/plugins/record/src/helpers/validation/index.ts +++ b/packages/payload/packages/xns/plugins/record/src/helpers/validation/index.ts @@ -1,2 +1,2 @@ -export * from './private/index.ts' -export * from './public/index.ts' +export * from './factory/index.ts' +export * from './validators/index.ts' diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/validation/public/index.ts b/packages/payload/packages/xns/plugins/record/src/helpers/validation/validators/index.ts similarity index 100% rename from packages/payload/packages/xns/plugins/record/src/helpers/validation/public/index.ts rename to packages/payload/packages/xns/plugins/record/src/helpers/validation/validators/index.ts diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/validation/public/spec/tsconfig.json b/packages/payload/packages/xns/plugins/record/src/helpers/validation/validators/spec/tsconfig.json similarity index 100% rename from packages/payload/packages/xns/plugins/record/src/helpers/validation/public/spec/tsconfig.json rename to packages/payload/packages/xns/plugins/record/src/helpers/validation/validators/spec/tsconfig.json diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/validation/public/spec/validators.spec.ts b/packages/payload/packages/xns/plugins/record/src/helpers/validation/validators/spec/validators.spec.ts similarity index 100% rename from packages/payload/packages/xns/plugins/record/src/helpers/validation/public/spec/validators.spec.ts rename to packages/payload/packages/xns/plugins/record/src/helpers/validation/validators/spec/validators.spec.ts diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/validation/public/validators.ts b/packages/payload/packages/xns/plugins/record/src/helpers/validation/validators/validators.ts similarity index 100% rename from packages/payload/packages/xns/plugins/record/src/helpers/validation/public/validators.ts rename to packages/payload/packages/xns/plugins/record/src/helpers/validation/validators/validators.ts From 0ae9eec7022e5e9aed7d8b7a319a9a7b9ef2e4bd Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Wed, 4 Sep 2024 09:54:32 -0500 Subject: [PATCH 23/46] Nest estimates --- .../packages/xns/plugins/record/src/estimate/index.ts | 1 + .../packages/xns/plugins/record/src/{ => estimate}/lib/index.ts | 0 .../record/src/{ => estimate}/lib/parseDomainEstimates.ts | 0 .../lib/spec/__snapshots__/parseDomainEstimates.spec.ts.snap | 0 .../src/{ => estimate}/lib/spec/parseDomainEstimates.spec.ts | 0 .../plugins/record/src/{ => estimate}/lib/spec/tsconfig.json | 0 packages/payloadset/packages/xns/plugins/record/src/index.ts | 2 +- 7 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 packages/payloadset/packages/xns/plugins/record/src/estimate/index.ts rename packages/payloadset/packages/xns/plugins/record/src/{ => estimate}/lib/index.ts (100%) rename packages/payloadset/packages/xns/plugins/record/src/{ => estimate}/lib/parseDomainEstimates.ts (100%) rename packages/payloadset/packages/xns/plugins/record/src/{ => estimate}/lib/spec/__snapshots__/parseDomainEstimates.spec.ts.snap (100%) rename packages/payloadset/packages/xns/plugins/record/src/{ => estimate}/lib/spec/parseDomainEstimates.spec.ts (100%) rename packages/payloadset/packages/xns/plugins/record/src/{ => estimate}/lib/spec/tsconfig.json (100%) diff --git a/packages/payloadset/packages/xns/plugins/record/src/estimate/index.ts b/packages/payloadset/packages/xns/plugins/record/src/estimate/index.ts new file mode 100644 index 000000000..ac9d58e65 --- /dev/null +++ b/packages/payloadset/packages/xns/plugins/record/src/estimate/index.ts @@ -0,0 +1 @@ +export * from './lib/index.ts' diff --git a/packages/payloadset/packages/xns/plugins/record/src/lib/index.ts b/packages/payloadset/packages/xns/plugins/record/src/estimate/lib/index.ts similarity index 100% rename from packages/payloadset/packages/xns/plugins/record/src/lib/index.ts rename to packages/payloadset/packages/xns/plugins/record/src/estimate/lib/index.ts diff --git a/packages/payloadset/packages/xns/plugins/record/src/lib/parseDomainEstimates.ts b/packages/payloadset/packages/xns/plugins/record/src/estimate/lib/parseDomainEstimates.ts similarity index 100% rename from packages/payloadset/packages/xns/plugins/record/src/lib/parseDomainEstimates.ts rename to packages/payloadset/packages/xns/plugins/record/src/estimate/lib/parseDomainEstimates.ts diff --git a/packages/payloadset/packages/xns/plugins/record/src/lib/spec/__snapshots__/parseDomainEstimates.spec.ts.snap b/packages/payloadset/packages/xns/plugins/record/src/estimate/lib/spec/__snapshots__/parseDomainEstimates.spec.ts.snap similarity index 100% rename from packages/payloadset/packages/xns/plugins/record/src/lib/spec/__snapshots__/parseDomainEstimates.spec.ts.snap rename to packages/payloadset/packages/xns/plugins/record/src/estimate/lib/spec/__snapshots__/parseDomainEstimates.spec.ts.snap diff --git a/packages/payloadset/packages/xns/plugins/record/src/lib/spec/parseDomainEstimates.spec.ts b/packages/payloadset/packages/xns/plugins/record/src/estimate/lib/spec/parseDomainEstimates.spec.ts similarity index 100% rename from packages/payloadset/packages/xns/plugins/record/src/lib/spec/parseDomainEstimates.spec.ts rename to packages/payloadset/packages/xns/plugins/record/src/estimate/lib/spec/parseDomainEstimates.spec.ts diff --git a/packages/payloadset/packages/xns/plugins/record/src/lib/spec/tsconfig.json b/packages/payloadset/packages/xns/plugins/record/src/estimate/lib/spec/tsconfig.json similarity index 100% rename from packages/payloadset/packages/xns/plugins/record/src/lib/spec/tsconfig.json rename to packages/payloadset/packages/xns/plugins/record/src/estimate/lib/spec/tsconfig.json diff --git a/packages/payloadset/packages/xns/plugins/record/src/index.ts b/packages/payloadset/packages/xns/plugins/record/src/index.ts index ac9d58e65..c5945c69d 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/index.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/index.ts @@ -1 +1 @@ -export * from './lib/index.ts' +export * from './estimate/index.ts' From a2aa48d2b72842fb7cea408cca33f5fdeb473811 Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Wed, 4 Sep 2024 09:55:08 -0500 Subject: [PATCH 24/46] Move validation helpers dir --- .../packages/xns/plugins/record/src/helpers/index.ts | 0 .../packages/xns/plugins/record/src/helpers/name/Name.ts | 4 ++-- .../xns/plugins/record/src/helpers/name/spec/Name.spec.ts | 4 ++-- .../xns/plugins/record/src/helpers/name/spec/tsconfig.json | 0 .../plugins/record/src/helpers/validation/factory/index.ts | 0 .../record/src/helpers/validation/factory/spec/tsconfig.json | 0 .../src/helpers/validation/factory/spec/validators.spec.ts | 0 .../record/src/helpers/validation/factory/validators.ts | 2 +- .../xns/plugins/record/src/helpers/validation/index.ts | 0 .../plugins/record/src/helpers/validation/validators/index.ts | 0 .../src/helpers/validation/validators/spec/tsconfig.json | 0 .../src/helpers/validation/validators/spec/validators.spec.ts | 0 .../record/src/helpers/validation/validators/validators.ts | 2 +- packages/payloadset/packages/xns/plugins/record/src/index.ts | 1 + 14 files changed, 7 insertions(+), 6 deletions(-) rename packages/{payload => payloadset}/packages/xns/plugins/record/src/helpers/index.ts (100%) rename packages/{payload => payloadset}/packages/xns/plugins/record/src/helpers/name/Name.ts (94%) rename packages/{payload => payloadset}/packages/xns/plugins/record/src/helpers/name/spec/Name.spec.ts (94%) rename packages/{payload => payloadset}/packages/xns/plugins/record/src/helpers/name/spec/tsconfig.json (100%) rename packages/{payload => payloadset}/packages/xns/plugins/record/src/helpers/validation/factory/index.ts (100%) rename packages/{payload => payloadset}/packages/xns/plugins/record/src/helpers/validation/factory/spec/tsconfig.json (100%) rename packages/{payload => payloadset}/packages/xns/plugins/record/src/helpers/validation/factory/spec/validators.spec.ts (100%) rename packages/{payload => payloadset}/packages/xns/plugins/record/src/helpers/validation/factory/validators.ts (92%) rename packages/{payload => payloadset}/packages/xns/plugins/record/src/helpers/validation/index.ts (100%) rename packages/{payload => payloadset}/packages/xns/plugins/record/src/helpers/validation/validators/index.ts (100%) rename packages/{payload => payloadset}/packages/xns/plugins/record/src/helpers/validation/validators/spec/tsconfig.json (100%) rename packages/{payload => payloadset}/packages/xns/plugins/record/src/helpers/validation/validators/spec/validators.spec.ts (100%) rename packages/{payload => payloadset}/packages/xns/plugins/record/src/helpers/validation/validators/validators.ts (95%) diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/index.ts b/packages/payloadset/packages/xns/plugins/record/src/helpers/index.ts similarity index 100% rename from packages/payload/packages/xns/plugins/record/src/helpers/index.ts rename to packages/payloadset/packages/xns/plugins/record/src/helpers/index.ts diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/name/Name.ts b/packages/payloadset/packages/xns/plugins/record/src/helpers/name/Name.ts similarity index 94% rename from packages/payload/packages/xns/plugins/record/src/helpers/name/Name.ts rename to packages/payloadset/packages/xns/plugins/record/src/helpers/name/Name.ts index 14613c5b4..d98eba482 100644 --- a/packages/payload/packages/xns/plugins/record/src/helpers/name/Name.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/helpers/name/Name.ts @@ -6,8 +6,8 @@ import { DisallowedModuleIdentifierCharacters } from '@xyo-network/module-model' import type { Domain, TopLevelDomain, -} from '../../Domain/index.ts' -import { DomainSchema } from '../../Domain/index.ts' +} from '../../../../../../../../payload/packages/xns/plugins/record/src/Domain/index.ts' +import { DomainSchema } from '../../../../../../../../payload/packages/xns/plugins/record/src/Domain/index.ts' import { XnsNamePublicValidators } from '../validation/index.ts' export type ValidSourceTypes = 'xnsName' | 'hash' | null diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/name/spec/Name.spec.ts b/packages/payloadset/packages/xns/plugins/record/src/helpers/name/spec/Name.spec.ts similarity index 94% rename from packages/payload/packages/xns/plugins/record/src/helpers/name/spec/Name.spec.ts rename to packages/payloadset/packages/xns/plugins/record/src/helpers/name/spec/Name.spec.ts index 38c52b34d..97fb963a8 100644 --- a/packages/payload/packages/xns/plugins/record/src/helpers/name/spec/Name.spec.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/helpers/name/spec/Name.spec.ts @@ -1,5 +1,5 @@ -import type { Domain } from '../../../Domain/index.ts' -import { DomainSchema } from '../../../Domain/index.ts' +import type { Domain } from '../../../../../../../../../payload/packages/xns/plugins/record/src/Domain/index.ts' +import { DomainSchema } from '../../../../../../../../../payload/packages/xns/plugins/record/src/Domain/index.ts' import { XnsNameHelper } from '../Name.ts' describe('XnsNameHelper', () => { diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/name/spec/tsconfig.json b/packages/payloadset/packages/xns/plugins/record/src/helpers/name/spec/tsconfig.json similarity index 100% rename from packages/payload/packages/xns/plugins/record/src/helpers/name/spec/tsconfig.json rename to packages/payloadset/packages/xns/plugins/record/src/helpers/name/spec/tsconfig.json diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/validation/factory/index.ts b/packages/payloadset/packages/xns/plugins/record/src/helpers/validation/factory/index.ts similarity index 100% rename from packages/payload/packages/xns/plugins/record/src/helpers/validation/factory/index.ts rename to packages/payloadset/packages/xns/plugins/record/src/helpers/validation/factory/index.ts diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/validation/factory/spec/tsconfig.json b/packages/payloadset/packages/xns/plugins/record/src/helpers/validation/factory/spec/tsconfig.json similarity index 100% rename from packages/payload/packages/xns/plugins/record/src/helpers/validation/factory/spec/tsconfig.json rename to packages/payloadset/packages/xns/plugins/record/src/helpers/validation/factory/spec/tsconfig.json diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/validation/factory/spec/validators.spec.ts b/packages/payloadset/packages/xns/plugins/record/src/helpers/validation/factory/spec/validators.spec.ts similarity index 100% rename from packages/payload/packages/xns/plugins/record/src/helpers/validation/factory/spec/validators.spec.ts rename to packages/payloadset/packages/xns/plugins/record/src/helpers/validation/factory/spec/validators.spec.ts diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/validation/factory/validators.ts b/packages/payloadset/packages/xns/plugins/record/src/helpers/validation/factory/validators.ts similarity index 92% rename from packages/payload/packages/xns/plugins/record/src/helpers/validation/factory/validators.ts rename to packages/payloadset/packages/xns/plugins/record/src/helpers/validation/factory/validators.ts index 9b83d83d9..e57df0b83 100644 --- a/packages/payload/packages/xns/plugins/record/src/helpers/validation/factory/validators.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/helpers/validation/factory/validators.ts @@ -4,7 +4,7 @@ import type { PayloadValidationFunction, WithSources } from '@xyo-network/payload-model' -import type { DomainRegistration } from '../../../DomainRegistration/index.ts' +import type { DomainRegistration } from '../../../../../../../../../payload/packages/xns/plugins/record/src/DomainRegistration/index.ts' export const getDomainRegistrationReservedStringsValidator = ( reservedStrings: string[], diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/validation/index.ts b/packages/payloadset/packages/xns/plugins/record/src/helpers/validation/index.ts similarity index 100% rename from packages/payload/packages/xns/plugins/record/src/helpers/validation/index.ts rename to packages/payloadset/packages/xns/plugins/record/src/helpers/validation/index.ts diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/validation/validators/index.ts b/packages/payloadset/packages/xns/plugins/record/src/helpers/validation/validators/index.ts similarity index 100% rename from packages/payload/packages/xns/plugins/record/src/helpers/validation/validators/index.ts rename to packages/payloadset/packages/xns/plugins/record/src/helpers/validation/validators/index.ts diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/validation/validators/spec/tsconfig.json b/packages/payloadset/packages/xns/plugins/record/src/helpers/validation/validators/spec/tsconfig.json similarity index 100% rename from packages/payload/packages/xns/plugins/record/src/helpers/validation/validators/spec/tsconfig.json rename to packages/payloadset/packages/xns/plugins/record/src/helpers/validation/validators/spec/tsconfig.json diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/validation/validators/spec/validators.spec.ts b/packages/payloadset/packages/xns/plugins/record/src/helpers/validation/validators/spec/validators.spec.ts similarity index 100% rename from packages/payload/packages/xns/plugins/record/src/helpers/validation/validators/spec/validators.spec.ts rename to packages/payloadset/packages/xns/plugins/record/src/helpers/validation/validators/spec/validators.spec.ts diff --git a/packages/payload/packages/xns/plugins/record/src/helpers/validation/validators/validators.ts b/packages/payloadset/packages/xns/plugins/record/src/helpers/validation/validators/validators.ts similarity index 95% rename from packages/payload/packages/xns/plugins/record/src/helpers/validation/validators/validators.ts rename to packages/payloadset/packages/xns/plugins/record/src/helpers/validation/validators/validators.ts index c2c54f300..69cc31c6f 100644 --- a/packages/payload/packages/xns/plugins/record/src/helpers/validation/validators/validators.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/helpers/validation/validators/validators.ts @@ -1,7 +1,7 @@ import { isModuleName } from '@xyo-network/module-model' import type { PayloadValidationFunction, WithSources } from '@xyo-network/payload-model' -import type { Domain } from '../../../Domain/index.ts' +import type { Domain } from '../../../../../../../../../payload/packages/xns/plugins/record/src/Domain/index.ts' export const domainRegistrationCasingValidator: PayloadValidationFunction> = ( domainRegistration: WithSources, diff --git a/packages/payloadset/packages/xns/plugins/record/src/index.ts b/packages/payloadset/packages/xns/plugins/record/src/index.ts index c5945c69d..9de8ff3f4 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/index.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/index.ts @@ -1 +1,2 @@ export * from './estimate/index.ts' +export * from './helpers/index.ts' From 1ccda50bb2bf6577c098889555c18f2133534083 Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Wed, 4 Sep 2024 09:55:41 -0500 Subject: [PATCH 25/46] Rename helpers directory --- packages/payloadset/packages/xns/plugins/record/src/index.ts | 2 +- .../xns/plugins/record/src/{helpers => validation}/index.ts | 0 .../xns/plugins/record/src/{helpers => validation}/name/Name.ts | 0 .../record/src/{helpers => validation}/name/spec/Name.spec.ts | 0 .../record/src/{helpers => validation}/name/spec/tsconfig.json | 0 .../src/{helpers => validation}/validation/factory/index.ts | 0 .../validation/factory/spec/tsconfig.json | 0 .../validation/factory/spec/validators.spec.ts | 0 .../{helpers => validation}/validation/factory/validators.ts | 0 .../record/src/{helpers => validation}/validation/index.ts | 0 .../src/{helpers => validation}/validation/validators/index.ts | 0 .../validation/validators/spec/tsconfig.json | 0 .../validation/validators/spec/validators.spec.ts | 0 .../{helpers => validation}/validation/validators/validators.ts | 0 14 files changed, 1 insertion(+), 1 deletion(-) rename packages/payloadset/packages/xns/plugins/record/src/{helpers => validation}/index.ts (100%) rename packages/payloadset/packages/xns/plugins/record/src/{helpers => validation}/name/Name.ts (100%) rename packages/payloadset/packages/xns/plugins/record/src/{helpers => validation}/name/spec/Name.spec.ts (100%) rename packages/payloadset/packages/xns/plugins/record/src/{helpers => validation}/name/spec/tsconfig.json (100%) rename packages/payloadset/packages/xns/plugins/record/src/{helpers => validation}/validation/factory/index.ts (100%) rename packages/payloadset/packages/xns/plugins/record/src/{helpers => validation}/validation/factory/spec/tsconfig.json (100%) rename packages/payloadset/packages/xns/plugins/record/src/{helpers => validation}/validation/factory/spec/validators.spec.ts (100%) rename packages/payloadset/packages/xns/plugins/record/src/{helpers => validation}/validation/factory/validators.ts (100%) rename packages/payloadset/packages/xns/plugins/record/src/{helpers => validation}/validation/index.ts (100%) rename packages/payloadset/packages/xns/plugins/record/src/{helpers => validation}/validation/validators/index.ts (100%) rename packages/payloadset/packages/xns/plugins/record/src/{helpers => validation}/validation/validators/spec/tsconfig.json (100%) rename packages/payloadset/packages/xns/plugins/record/src/{helpers => validation}/validation/validators/spec/validators.spec.ts (100%) rename packages/payloadset/packages/xns/plugins/record/src/{helpers => validation}/validation/validators/validators.ts (100%) diff --git a/packages/payloadset/packages/xns/plugins/record/src/index.ts b/packages/payloadset/packages/xns/plugins/record/src/index.ts index 9de8ff3f4..96f376156 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/index.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/index.ts @@ -1,2 +1,2 @@ export * from './estimate/index.ts' -export * from './helpers/index.ts' +export * from './validation/index.ts' diff --git a/packages/payloadset/packages/xns/plugins/record/src/helpers/index.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/index.ts similarity index 100% rename from packages/payloadset/packages/xns/plugins/record/src/helpers/index.ts rename to packages/payloadset/packages/xns/plugins/record/src/validation/index.ts diff --git a/packages/payloadset/packages/xns/plugins/record/src/helpers/name/Name.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts similarity index 100% rename from packages/payloadset/packages/xns/plugins/record/src/helpers/name/Name.ts rename to packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts diff --git a/packages/payloadset/packages/xns/plugins/record/src/helpers/name/spec/Name.spec.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/name/spec/Name.spec.ts similarity index 100% rename from packages/payloadset/packages/xns/plugins/record/src/helpers/name/spec/Name.spec.ts rename to packages/payloadset/packages/xns/plugins/record/src/validation/name/spec/Name.spec.ts diff --git a/packages/payloadset/packages/xns/plugins/record/src/helpers/name/spec/tsconfig.json b/packages/payloadset/packages/xns/plugins/record/src/validation/name/spec/tsconfig.json similarity index 100% rename from packages/payloadset/packages/xns/plugins/record/src/helpers/name/spec/tsconfig.json rename to packages/payloadset/packages/xns/plugins/record/src/validation/name/spec/tsconfig.json diff --git a/packages/payloadset/packages/xns/plugins/record/src/helpers/validation/factory/index.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/factory/index.ts similarity index 100% rename from packages/payloadset/packages/xns/plugins/record/src/helpers/validation/factory/index.ts rename to packages/payloadset/packages/xns/plugins/record/src/validation/validation/factory/index.ts diff --git a/packages/payloadset/packages/xns/plugins/record/src/helpers/validation/factory/spec/tsconfig.json b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/factory/spec/tsconfig.json similarity index 100% rename from packages/payloadset/packages/xns/plugins/record/src/helpers/validation/factory/spec/tsconfig.json rename to packages/payloadset/packages/xns/plugins/record/src/validation/validation/factory/spec/tsconfig.json diff --git a/packages/payloadset/packages/xns/plugins/record/src/helpers/validation/factory/spec/validators.spec.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/factory/spec/validators.spec.ts similarity index 100% rename from packages/payloadset/packages/xns/plugins/record/src/helpers/validation/factory/spec/validators.spec.ts rename to packages/payloadset/packages/xns/plugins/record/src/validation/validation/factory/spec/validators.spec.ts diff --git a/packages/payloadset/packages/xns/plugins/record/src/helpers/validation/factory/validators.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/factory/validators.ts similarity index 100% rename from packages/payloadset/packages/xns/plugins/record/src/helpers/validation/factory/validators.ts rename to packages/payloadset/packages/xns/plugins/record/src/validation/validation/factory/validators.ts diff --git a/packages/payloadset/packages/xns/plugins/record/src/helpers/validation/index.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/index.ts similarity index 100% rename from packages/payloadset/packages/xns/plugins/record/src/helpers/validation/index.ts rename to packages/payloadset/packages/xns/plugins/record/src/validation/validation/index.ts diff --git a/packages/payloadset/packages/xns/plugins/record/src/helpers/validation/validators/index.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/index.ts similarity index 100% rename from packages/payloadset/packages/xns/plugins/record/src/helpers/validation/validators/index.ts rename to packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/index.ts diff --git a/packages/payloadset/packages/xns/plugins/record/src/helpers/validation/validators/spec/tsconfig.json b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/spec/tsconfig.json similarity index 100% rename from packages/payloadset/packages/xns/plugins/record/src/helpers/validation/validators/spec/tsconfig.json rename to packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/spec/tsconfig.json diff --git a/packages/payloadset/packages/xns/plugins/record/src/helpers/validation/validators/spec/validators.spec.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/spec/validators.spec.ts similarity index 100% rename from packages/payloadset/packages/xns/plugins/record/src/helpers/validation/validators/spec/validators.spec.ts rename to packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/spec/validators.spec.ts diff --git a/packages/payloadset/packages/xns/plugins/record/src/helpers/validation/validators/validators.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/validators.ts similarity index 100% rename from packages/payloadset/packages/xns/plugins/record/src/helpers/validation/validators/validators.ts rename to packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/validators.ts From 342a9664d15328dadd263d06de251dc130845acf Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Wed, 4 Sep 2024 09:58:00 -0500 Subject: [PATCH 26/46] Remove migrated export --- packages/payload/packages/xns/plugins/record/src/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/payload/packages/xns/plugins/record/src/index.ts b/packages/payload/packages/xns/plugins/record/src/index.ts index 14eceafa0..fbd41abe3 100644 --- a/packages/payload/packages/xns/plugins/record/src/index.ts +++ b/packages/payload/packages/xns/plugins/record/src/index.ts @@ -6,4 +6,3 @@ export * from './DomainEstimate/index.ts' export * from './DomainRegistration/index.ts' export * from './Duration/index.ts' export * from './Hash/index.ts' -export * from './helpers/index.ts' From 13186626a5311b4c130d5a718ec58a91e9b1ec87 Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Wed, 4 Sep 2024 10:11:16 -0500 Subject: [PATCH 27/46] Update deps/paths --- .../packages/xns/plugins/record/package.json | 2 - .../packages/xns/plugins/record/package.json | 4 + .../record/src/validation/name/Name.ts | 6 +- .../src/validation/name/spec/Name.spec.ts | 5 +- .../factory/spec/validators.spec.ts | 4 +- .../validation/factory/validators.ts | 3 +- .../validators/spec/validators.spec.ts | 4 +- .../validation/validators/validators.ts | 3 +- yarn.lock | 137 ++++++++++++++++-- 9 files changed, 142 insertions(+), 26 deletions(-) diff --git a/packages/payload/packages/xns/plugins/record/package.json b/packages/payload/packages/xns/plugins/record/package.json index 767e01faa..d1eb6ff49 100644 --- a/packages/payload/packages/xns/plugins/record/package.json +++ b/packages/payload/packages/xns/plugins/record/package.json @@ -29,10 +29,8 @@ "module": "dist/neutral/index.mjs", "types": "dist/neutral/index.d.ts", "dependencies": { - "@xylabs/assert": "4.0.9", "@xylabs/exists": "^4.0.9", "@xylabs/hex": "^4.0.9", - "@xylabs/promise": "^4.0.9", "@xyo-network/boundwitness-model": "^3.1.4", "@xyo-network/boundwitness-validator": "^3.1.4", "@xyo-network/diviner-hash-lease": "^3.1.4", diff --git a/packages/payloadset/packages/xns/plugins/record/package.json b/packages/payloadset/packages/xns/plugins/record/package.json index 4df046d96..bcb5d32f6 100644 --- a/packages/payloadset/packages/xns/plugins/record/package.json +++ b/packages/payloadset/packages/xns/plugins/record/package.json @@ -29,9 +29,13 @@ "module": "dist/neutral/index.mjs", "types": "dist/neutral/index.d.ts", "dependencies": { + "@xylabs/assert": "^4.0.9", "@xylabs/exists": "^4.0.9", + "@xylabs/hex": "^4.0.9", + "@xylabs/promise": "^4.0.9", "@xyo-network/boundwitness-model": "^3.1.4", "@xyo-network/diviner-hash-lease": "^3.1.4", + "@xyo-network/module-model": "^3.1.5", "@xyo-network/payload-builder": "^3.1.4", "@xyo-network/payload-model": "^3.1.4", "@xyo-network/xns-record-payload-plugins": "workspace:^" diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts index d98eba482..02a657a4e 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts @@ -2,12 +2,12 @@ import { assertEx } from '@xylabs/assert' import { isHash } from '@xylabs/hex' import type { Promisable } from '@xylabs/promise' import { DisallowedModuleIdentifierCharacters } from '@xyo-network/module-model' - import type { Domain, TopLevelDomain, -} from '../../../../../../../../payload/packages/xns/plugins/record/src/Domain/index.ts' -import { DomainSchema } from '../../../../../../../../payload/packages/xns/plugins/record/src/Domain/index.ts' +} from '@xyo-network/xns-record-payload-plugins' +import { DomainSchema } from '@xyo-network/xns-record-payload-plugins' + import { XnsNamePublicValidators } from '../validation/index.ts' export type ValidSourceTypes = 'xnsName' | 'hash' | null diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/name/spec/Name.spec.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/name/spec/Name.spec.ts index 97fb963a8..30acae0a7 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/validation/name/spec/Name.spec.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/name/spec/Name.spec.ts @@ -1,5 +1,6 @@ -import type { Domain } from '../../../../../../../../../payload/packages/xns/plugins/record/src/Domain/index.ts' -import { DomainSchema } from '../../../../../../../../../payload/packages/xns/plugins/record/src/Domain/index.ts' +import type { Domain } from '@xyo-network/xns-record-payload-plugins' +import { DomainSchema } from '@xyo-network/xns-record-payload-plugins' + import { XnsNameHelper } from '../Name.ts' describe('XnsNameHelper', () => { diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/validation/factory/spec/validators.spec.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/factory/spec/validators.spec.ts index 507d85b35..6b2bca9a3 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/validation/validation/factory/spec/validators.spec.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/factory/spec/validators.spec.ts @@ -1,7 +1,7 @@ import type { WithSources } from '@xyo-network/payload-model' +import type { DomainRegistration } from '@xyo-network/xns-record-payload-plugins' +import { DomainRegistrationSchema } from '@xyo-network/xns-record-payload-plugins' -import type { DomainRegistration } from '../../../../DomainRegistration/index.ts' -import { DomainRegistrationSchema } from '../../../../DomainRegistration/index.ts' import { getDomainRegistrationReservedFragmentsValidator, getDomainRegistrationReservedNamesValidator, getDomainRegistrationReservedStringsValidator, } from '../index.ts' diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/validation/factory/validators.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/factory/validators.ts index e57df0b83..d985f7ab6 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/validation/validation/factory/validators.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/factory/validators.ts @@ -3,8 +3,7 @@ */ import type { PayloadValidationFunction, WithSources } from '@xyo-network/payload-model' - -import type { DomainRegistration } from '../../../../../../../../../payload/packages/xns/plugins/record/src/DomainRegistration/index.ts' +import type { DomainRegistration } from '@xyo-network/xns-record-payload-plugins' export const getDomainRegistrationReservedStringsValidator = ( reservedStrings: string[], diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/spec/validators.spec.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/spec/validators.spec.ts index 938a28308..8727a9ec2 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/spec/validators.spec.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/spec/validators.spec.ts @@ -4,9 +4,9 @@ */ import type { WithSources } from '@xyo-network/payload-model' +import type { DomainRegistration } from '@xyo-network/xns-record-payload-plugins' +import { DomainRegistrationSchema } from '@xyo-network/xns-record-payload-plugins' -import type { DomainRegistration } from '../../../../DomainRegistration/index.ts' -import { DomainRegistrationSchema } from '../../../../DomainRegistration/index.ts' import { domainRegistrationCasingValidator, domainRegistrationModuleNameValidator, diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/validators.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/validators.ts index 69cc31c6f..7222ab52c 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/validators.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/validators.ts @@ -1,7 +1,6 @@ import { isModuleName } from '@xyo-network/module-model' import type { PayloadValidationFunction, WithSources } from '@xyo-network/payload-model' - -import type { Domain } from '../../../../../../../../../payload/packages/xns/plugins/record/src/Domain/index.ts' +import type { Domain } from '@xyo-network/xns-record-payload-plugins' export const domainRegistrationCasingValidator: PayloadValidationFunction> = ( domainRegistration: WithSources, diff --git a/yarn.lock b/yarn.lock index 1ecb57b2c..e73e7b043 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3807,7 +3807,7 @@ __metadata: languageName: node linkType: hard -"@xylabs/arraybuffer@npm:^4.0.5": +"@xylabs/arraybuffer@npm:^4.0.5, @xylabs/arraybuffer@npm:^4.0.9": version: 4.0.9 resolution: "@xylabs/arraybuffer@npm:4.0.9" dependencies: @@ -3819,13 +3819,6 @@ __metadata: languageName: node linkType: hard -"@xylabs/assert@npm:4.0.9, @xylabs/assert@npm:^4.0.5, @xylabs/assert@npm:^4.0.9": - version: 4.0.9 - resolution: "@xylabs/assert@npm:4.0.9" - checksum: 10/1287f1bab9fe1fd6580edd0ef2a8ea408928bf4540fb613e9a7f16e648c76256311104dda7b3cd032e888ba4992dfe66e95c4a9489f80fab1298dc0d0c137994 - languageName: node - linkType: hard - "@xylabs/assert@npm:^3.0.14": version: 3.6.12 resolution: "@xylabs/assert@npm:3.6.12" @@ -3833,6 +3826,13 @@ __metadata: languageName: node linkType: hard +"@xylabs/assert@npm:^4.0.5, @xylabs/assert@npm:^4.0.9": + version: 4.0.9 + resolution: "@xylabs/assert@npm:4.0.9" + checksum: 10/1287f1bab9fe1fd6580edd0ef2a8ea408928bf4540fb613e9a7f16e648c76256311104dda7b3cd032e888ba4992dfe66e95c4a9489f80fab1298dc0d0c137994 + languageName: node + linkType: hard + "@xylabs/axios@npm:^4.0.5, @xylabs/axios@npm:^4.0.9": version: 4.0.9 resolution: "@xylabs/axios@npm:4.0.9" @@ -3985,7 +3985,7 @@ __metadata: languageName: node linkType: hard -"@xylabs/retry@npm:^4.0.5": +"@xylabs/retry@npm:^4.0.5, @xylabs/retry@npm:^4.0.9": version: 4.0.9 resolution: "@xylabs/retry@npm:4.0.9" dependencies: @@ -4250,6 +4250,23 @@ __metadata: languageName: node linkType: hard +"@xyo-network/account-model@npm:^3.1.5": + version: 3.1.5 + resolution: "@xyo-network/account-model@npm:3.1.5" + dependencies: + "@xylabs/hex": "npm:^4.0.9" + "@xylabs/lodash": "npm:^4.0.9" + "@xyo-network/key-model": "npm:^3.1.5" + "@xyo-network/previous-hash-store-model": "npm:^3.1.5" + peerDependencies: + ethers: ^6 + peerDependenciesMeta: + ethers: + optional: true + checksum: 10/95fd21376a622685f2e3c43e7ea3dd09d0e79c01e48233fc22c67bc789942838783a57779c78464c35a491cac899b55562d50d3f6fa832e6d3c00dec8575a2b0 + languageName: node + linkType: hard + "@xyo-network/account@npm:^3.1.4": version: 3.1.4 resolution: "@xyo-network/account@npm:3.1.4" @@ -4506,6 +4523,17 @@ __metadata: languageName: node linkType: hard +"@xyo-network/boundwitness-model@npm:^3.1.5": + version: 3.1.5 + resolution: "@xyo-network/boundwitness-model@npm:3.1.5" + dependencies: + "@xylabs/hex": "npm:^4.0.9" + "@xylabs/object": "npm:^4.0.9" + "@xyo-network/payload-model": "npm:^3.1.5" + checksum: 10/8638dafbff2213429b3d9cd492b329602b688d805c5ff6f280c4d51448f181109c2d7fd84ed7e23d3a3081291b0bdaf95c4649c5d94fd186f261f3ebd9b559b6 + languageName: node + linkType: hard + "@xyo-network/boundwitness-validator@npm:^3.1.4": version: 3.1.4 resolution: "@xyo-network/boundwitness-validator@npm:3.1.4" @@ -5212,6 +5240,19 @@ __metadata: languageName: node linkType: hard +"@xyo-network/data@npm:^3.1.5": + version: 3.1.5 + resolution: "@xyo-network/data@npm:3.1.5" + dependencies: + "@scure/base": "npm:^1.1.7" + "@xylabs/arraybuffer": "npm:^4.0.9" + "@xylabs/assert": "npm:^4.0.9" + "@xylabs/hex": "npm:^4.0.9" + ethers: "npm:6.13.2" + checksum: 10/d32e4a0698e37c33838bdbd42bfb6c1c69bd635aa6ebd9e749b2e840e845cde777b4b91f3975819ddefa49df3ac4f4ca34ef95bdf10ee837e5002a577134a170 + languageName: node + linkType: hard + "@xyo-network/diviner-abstract@npm:^3.1.4": version: 3.1.4 resolution: "@xyo-network/diviner-abstract@npm:3.1.4" @@ -6489,6 +6530,15 @@ __metadata: languageName: node linkType: hard +"@xyo-network/key-model@npm:^3.1.5": + version: 3.1.5 + resolution: "@xyo-network/key-model@npm:3.1.5" + dependencies: + "@xyo-network/data": "npm:^3.1.5" + checksum: 10/898dfea1f364340b3bf26e48c24517f2d9d847777097ef466b31c46d5cb33c4f1e997c2e1020f83b1ae65a3f4e8da30dff7974fd80aca5108907c933342f0b8b + languageName: node + linkType: hard + "@xyo-network/location-certainty-payload-plugin@workspace:^, @xyo-network/location-certainty-payload-plugin@workspace:packages/payload/packages/location-certainty": version: 0.0.0-use.local resolution: "@xyo-network/location-certainty-payload-plugin@workspace:packages/payload/packages/location-certainty" @@ -6566,6 +6616,16 @@ __metadata: languageName: node linkType: hard +"@xyo-network/manifest-model@npm:^3.1.5": + version: 3.1.5 + resolution: "@xyo-network/manifest-model@npm:3.1.5" + dependencies: + "@xylabs/hex": "npm:^4.0.9" + "@xyo-network/payload-model": "npm:^3.1.5" + checksum: 10/6e26b4dc2a0be004cc86387e4b6e665d78903c5b624e83f680f7c7b98833cca1865cbe4b172739174bcf8d916054b5019bb4489331255e65f63995c8d05bf1ee + languageName: node + linkType: hard + "@xyo-network/manifest-wrapper@npm:^3.1.4": version: 3.1.4 resolution: "@xyo-network/manifest-wrapper@npm:3.1.4" @@ -6641,6 +6701,19 @@ __metadata: languageName: node linkType: hard +"@xyo-network/module-events@npm:^3.1.5": + version: 3.1.5 + resolution: "@xyo-network/module-events@npm:3.1.5" + dependencies: + "@xylabs/assert": "npm:^4.0.9" + "@xylabs/error": "npm:^4.0.9" + "@xylabs/forget": "npm:^4.0.9" + "@xylabs/object": "npm:^4.0.9" + "@xylabs/promise": "npm:^4.0.9" + checksum: 10/3339f9f36b3979c404bf2ab69544174c4069f316263a695dc9428836d637050c63e6dc1e22580023e94c1969f566b644a3e5192abeb1211d33d252c4b43e201c + languageName: node + linkType: hard + "@xyo-network/module-factory-locator@npm:^3.1.4": version: 3.1.4 resolution: "@xyo-network/module-factory-locator@npm:3.1.4" @@ -6715,6 +6788,27 @@ __metadata: languageName: node linkType: hard +"@xyo-network/module-model@npm:^3.1.5": + version: 3.1.5 + resolution: "@xyo-network/module-model@npm:3.1.5" + dependencies: + "@xylabs/assert": "npm:^4.0.9" + "@xylabs/exists": "npm:^4.0.9" + "@xylabs/hex": "npm:^4.0.9" + "@xylabs/lodash": "npm:^4.0.9" + "@xylabs/logger": "npm:^4.0.9" + "@xylabs/object": "npm:^4.0.9" + "@xylabs/promise": "npm:^4.0.9" + "@xylabs/retry": "npm:^4.0.9" + "@xyo-network/account-model": "npm:^3.1.5" + "@xyo-network/boundwitness-model": "npm:^3.1.5" + "@xyo-network/manifest-model": "npm:^3.1.5" + "@xyo-network/module-events": "npm:^3.1.5" + "@xyo-network/payload-model": "npm:^3.1.5" + checksum: 10/43c2f4409eb016d98e91062ce2e90e436e8673eabb638e56356e4ba1581f06f02983828eff825e0caf1ac68bb0d78075124f751681e37507001c562d2e155534 + languageName: node + linkType: hard + "@xyo-network/module-resolver@npm:^3.1.4": version: 3.1.4 resolution: "@xyo-network/module-resolver@npm:3.1.4" @@ -6923,6 +7017,16 @@ __metadata: languageName: node linkType: hard +"@xyo-network/payload-model@npm:^3.1.5": + version: 3.1.5 + resolution: "@xyo-network/payload-model@npm:3.1.5" + dependencies: + "@xylabs/hex": "npm:^4.0.9" + "@xylabs/object": "npm:^4.0.9" + checksum: 10/fe534cba9e0e53388912ac255be9192a280c14715296d2cd5eb892f16a391a2f7f2805a68f4ffb4259d80f0b5da23d6501957142b35648f84b61ef529606bcce + languageName: node + linkType: hard + "@xyo-network/payload-plugin@npm:^3.1.4": version: 3.1.4 resolution: "@xyo-network/payload-plugin@npm:3.1.4" @@ -7183,6 +7287,15 @@ __metadata: languageName: node linkType: hard +"@xyo-network/previous-hash-store-model@npm:^3.1.5": + version: 3.1.5 + resolution: "@xyo-network/previous-hash-store-model@npm:3.1.5" + dependencies: + "@xylabs/hex": "npm:^4.0.9" + checksum: 10/23d3f65c76303a02f762862bb90893c7745da3fdd6f3553538fde83ed539563ab015a5aa7799da8b0d94e123acfd978dd3d9f8cbb327493aa4732005f2401d23 + languageName: node + linkType: hard + "@xyo-network/previous-hash-store-storage@npm:^3.1.4": version: 3.1.4 resolution: "@xyo-network/previous-hash-store-storage@npm:3.1.4" @@ -7791,10 +7904,8 @@ __metadata: version: 0.0.0-use.local resolution: "@xyo-network/xns-record-payload-plugins@workspace:packages/payload/packages/xns/plugins/record" dependencies: - "@xylabs/assert": "npm:4.0.9" "@xylabs/exists": "npm:^4.0.9" "@xylabs/hex": "npm:^4.0.9" - "@xylabs/promise": "npm:^4.0.9" "@xylabs/ts-scripts-yarn3": "npm:^4.0.7" "@xylabs/tsconfig": "npm:^4.0.7" "@xyo-network/account": "npm:^3.1.4" @@ -7814,11 +7925,15 @@ __metadata: version: 0.0.0-use.local resolution: "@xyo-network/xns-record-payloadset-plugins@workspace:packages/payloadset/packages/xns/plugins/record" dependencies: + "@xylabs/assert": "npm:^4.0.9" "@xylabs/exists": "npm:^4.0.9" + "@xylabs/hex": "npm:^4.0.9" + "@xylabs/promise": "npm:^4.0.9" "@xylabs/ts-scripts-yarn3": "npm:^4.0.7" "@xylabs/tsconfig": "npm:^4.0.7" "@xyo-network/boundwitness-model": "npm:^3.1.4" "@xyo-network/diviner-hash-lease": "npm:^3.1.4" + "@xyo-network/module-model": "npm:^3.1.5" "@xyo-network/payload-builder": "npm:^3.1.4" "@xyo-network/payload-model": "npm:^3.1.4" "@xyo-network/xns-record-payload-plugins": "workspace:^" From ed1b82dde342a8e09fc3c6c981e3639d833caddf Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Wed, 4 Sep 2024 10:17:20 -0500 Subject: [PATCH 28/46] Use generic payload --- .../xns/plugins/record/src/validation/name/Name.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts index 02a657a4e..b7176143b 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts @@ -2,8 +2,10 @@ import { assertEx } from '@xylabs/assert' import { isHash } from '@xylabs/hex' import type { Promisable } from '@xylabs/promise' import { DisallowedModuleIdentifierCharacters } from '@xyo-network/module-model' +import type { Payload } from '@xyo-network/payload-model' import type { Domain, + DomainFields, TopLevelDomain, } from '@xyo-network/xns-record-payload-plugins' import { DomainSchema } from '@xyo-network/xns-record-payload-plugins' @@ -27,8 +29,11 @@ export class XnsNameHelper { private _xnsName: Domain - private constructor(xnsName: Domain) { - this._xnsName = xnsName + private constructor(xnsName: Payload) { + const { domain, tld } = xnsName + this._xnsName = { + domain, tld, schema: DomainSchema, + } } get domain() { @@ -48,7 +53,7 @@ export class XnsNameHelper { * @param {Domain} domain * @returns Promise */ - static fromPayload(domain: Domain): Promisable { + static fromPayload(domain: Payload): Promisable { return new XnsNameHelper(domain) } From 78895c89d54d4f810799c3a9f4102145e7a74f44 Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Wed, 4 Sep 2024 11:20:26 -0500 Subject: [PATCH 29/46] Add name helper --- .vscode/launch.json | 2 +- .../xns/plugins/record/src/validation/name/Name.ts | 11 ++++++----- .../record/src/validation/name/spec/Name.spec.ts | 6 +++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 4e608c98c..7a17ead31 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -94,7 +94,7 @@ "--run", "--inspect-brk", "--no-file-parallelism", - "packages/payload/packages/xns/plugins/record/src/diviner/lib/spec/parseEstimatesFromArray.spec.ts" + "packages/payloadset/packages/xns/plugins/record/src/validation/name/spec/Name.spec.ts" ], "sourceMaps": true, "resolveSourceMapLocations": [ diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts index b7176143b..39bb68e11 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts @@ -27,19 +27,20 @@ const REMOVE_DISALLOWED_CHARS = new RegExp(`[${disallowedCharsPattern}]`, 'g') export class XnsNameHelper { static ValidTLDs = ['.xyo'] as const - private _xnsName: Domain + private _xnsName: Payload private constructor(xnsName: Payload) { - const { domain, tld } = xnsName - this._xnsName = { - domain, tld, schema: DomainSchema, - } + this._xnsName = xnsName } get domain() { return assertEx(this.xnsName.domain, () => 'domain not found in payload') } + get name() { + return `${this.domain}.${this.tld}` + } + get tld() { return assertEx(this.xnsName.tld, () => 'tld not found in payload') } diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/name/spec/Name.spec.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/name/spec/Name.spec.ts index 30acae0a7..a13068949 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/validation/name/spec/Name.spec.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/name/spec/Name.spec.ts @@ -46,7 +46,7 @@ describe('XnsNameHelper', () => { schema: DomainSchema, domain: 'example', tld: 'xyo', } const helper = await XnsNameHelper.fromPayload(domain) - expect(helper.xnsName).toBe(domain) + expect(helper.xnsName).toEqual(domain) }) it('should throw an error if xnsName is not set', async () => { @@ -65,8 +65,8 @@ describe('XnsNameHelper', () => { expect(helper.xnsName.tld).toBe(domain.tld) }) - it('should throw an error if xnsName string is invalid', async () => { - await expect(XnsNameHelper.fromString('invalid')).rejects.toThrow('Unable to parse xnsName') + it.only('should throw an error if xnsName string is invalid', () => { + expect(() => XnsNameHelper.fromString('invalid')).toThrow('Unable to parse xnsName') }) }) From b7c8e936ccb492d7a89e2ffd2e3a755ba2b7a80d Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Wed, 4 Sep 2024 11:24:33 -0500 Subject: [PATCH 30/46] DRY up test data --- .../src/validation/name/spec/Name.spec.ts | 41 ++++++++----------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/name/spec/Name.spec.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/name/spec/Name.spec.ts index a13068949..40ce9ac7a 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/validation/name/spec/Name.spec.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/name/spec/Name.spec.ts @@ -4,12 +4,12 @@ import { DomainSchema } from '@xyo-network/xns-record-payload-plugins' import { XnsNameHelper } from '../Name.ts' describe('XnsNameHelper', () => { + const validDomain: Domain = { + schema: DomainSchema, domain: 'example', tld: 'xyo', + } describe('domain getter', () => { it('should return the domain if set', async () => { - const domain: Domain = { - schema: DomainSchema, domain: 'example', tld: 'xyo', - } - const helper = await XnsNameHelper.fromPayload(domain) + const helper = await XnsNameHelper.fromPayload(validDomain) expect(helper.domain).toBe('example') }) @@ -24,10 +24,7 @@ describe('XnsNameHelper', () => { describe('tld getter', () => { it('should return the tld if set', async () => { - const domain: Domain = { - schema: DomainSchema, domain: 'example', tld: 'xyo', - } - const helper = await XnsNameHelper.fromPayload(domain) + const helper = await XnsNameHelper.fromPayload(validDomain) expect(helper.tld).toBe('xyo') }) @@ -42,11 +39,8 @@ describe('XnsNameHelper', () => { describe('xnsName getter', () => { it('should return the xnsName if set', async () => { - const domain: Domain = { - schema: DomainSchema, domain: 'example', tld: 'xyo', - } - const helper = await XnsNameHelper.fromPayload(domain) - expect(helper.xnsName).toEqual(domain) + const helper = await XnsNameHelper.fromPayload(validDomain) + expect(helper.xnsName).toEqual(validDomain) }) it('should throw an error if xnsName is not set', async () => { @@ -56,16 +50,16 @@ describe('XnsNameHelper', () => { }) describe('fromString', () => { - it('should create an instance from a valid xnsName string', async () => { - const domain: Domain = { - schema: DomainSchema, domain: 'example', tld: 'xyo', - } - const helper = await XnsNameHelper.fromString('example.xyo') - expect(helper.xnsName.domain).toBe(domain.domain) - expect(helper.xnsName.tld).toBe(domain.tld) + it('should create an instance from a valid xnsName string', () => { + const { domain, tld } = validDomain + const helper = XnsNameHelper.fromString(`${domain}.${tld}`) + expect(helper.domain).toBe(domain) + expect(helper.xnsName.domain).toBe(domain) + expect(helper.tld).toBe(tld) + expect(helper.xnsName.tld).toBe(tld) }) - it.only('should throw an error if xnsName string is invalid', () => { + it('should throw an error if xnsName string is invalid', () => { expect(() => XnsNameHelper.fromString('invalid')).toThrow('Unable to parse xnsName') }) }) @@ -86,10 +80,7 @@ describe('XnsNameHelper', () => { describe('isValid', () => { it('should return true for valid xns names', () => { - const domain: Domain = { - schema: DomainSchema, domain: 'example', tld: 'xyo', - } - expect(XnsNameHelper.isValid(domain)).toBe(true) + expect(XnsNameHelper.isValid(validDomain)).toBe(true) }) it('should return false for invalid xns names', () => { From ed337f56a235e8e75bc12c06ea0cd59c373ccf2c Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Wed, 4 Sep 2024 11:29:41 -0500 Subject: [PATCH 31/46] Update types to be more permissive --- .../validation/factory/validators.ts | 24 ++++------ .../validators/spec/validators.spec.ts | 24 +++++----- .../validation/validators/validators.ts | 46 +++++++++---------- 3 files changed, 45 insertions(+), 49 deletions(-) diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/validation/factory/validators.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/factory/validators.ts index d985f7ab6..401ada572 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/validation/validation/factory/validators.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/factory/validators.ts @@ -1,14 +1,10 @@ -/** - * NOTE: These validators are private because they rely on private data that cannot be shared with clients. - */ +import type { Payload, PayloadValidationFunction } from '@xyo-network/payload-model' +import type { DomainFields } from '@xyo-network/xns-record-payload-plugins' -import type { PayloadValidationFunction, WithSources } from '@xyo-network/payload-model' -import type { DomainRegistration } from '@xyo-network/xns-record-payload-plugins' - -export const getDomainRegistrationReservedStringsValidator = ( +export const getDomainReservedStringsValidator = ( reservedStrings: string[], -): PayloadValidationFunction> => { - return (domainRegistration: WithSources) => { +): PayloadValidationFunction> => { + return (domainRegistration: Payload) => { const { domain } = domainRegistration // Check if in one of the reserved name lists if (reservedStrings.includes(domain)) { @@ -19,10 +15,10 @@ export const getDomainRegistrationReservedStringsValidator = ( } } -export const getDomainRegistrationReservedFragmentsValidator = ( +export const getDomainReservedFragmentsValidator = ( reservedFragments: string[], -): PayloadValidationFunction> => { - return (domainRegistration: WithSources) => { +): PayloadValidationFunction> => { + return (domainRegistration: Payload) => { const { domain } = domainRegistration // Check if any of our fragments are in the name for (const reserved of reservedFragments) { @@ -35,8 +31,8 @@ export const getDomainRegistrationReservedFragmentsValidator = ( } } -export const getDomainRegistrationReservedNamesValidator = (reservedNames: string[]): PayloadValidationFunction> => { - return (domainRegistration: WithSources) => { +export const getDomainReservedNamesValidator = (reservedNames: string[]): PayloadValidationFunction> => { + return (domainRegistration: Payload) => { const { domain } = domainRegistration // Check if any of our fragments are in the name for (const reserved of reservedNames) { diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/spec/validators.spec.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/spec/validators.spec.ts index 8727a9ec2..0074bd753 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/spec/validators.spec.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/spec/validators.spec.ts @@ -8,11 +8,11 @@ import type { DomainRegistration } from '@xyo-network/xns-record-payload-plugins import { DomainRegistrationSchema } from '@xyo-network/xns-record-payload-plugins' import { - domainRegistrationCasingValidator, - domainRegistrationModuleNameValidator, - domainRegistrationTldValidator, - getDomainRegistrationAllowedHyphensValidator, - getDomainRegistrationLengthValidator, + domainCasingValidator, + domainModuleNameValidator, + domainTldValidator, + getDomainAllowedHyphensValidator, + getDomainLengthValidator, } from '../index.ts' const baseDomainRegistrationFields: DomainRegistration = { @@ -28,13 +28,13 @@ describe('XNS Name Validators', () => { const cases = [ { name: 'domainRegistrationCasingValidator', - validator: domainRegistrationCasingValidator, + validator: domainCasingValidator, valid: ['example'], invalid: ['Example'], }, { name: 'domainRegistrationModuleNameValidator', - validator: domainRegistrationModuleNameValidator, + validator: domainModuleNameValidator, valid: ['valid-domain'], invalid: ['invalid_domain'], }, @@ -70,14 +70,14 @@ describe('XNS Name Validators', () => { describe('Valid', () => { it.each(valid)('should return true for %s', (tld) => { const domainRegistration: WithSources = { ...baseDomainRegistrationFields, tld: tld as unknown as 'xyo' } - expect(domainRegistrationTldValidator(domainRegistration)).toBe(true) + expect(domainTldValidator(domainRegistration)).toBe(true) }) }) describe('Invalid', () => { it.each(invalid)('should return false for %s', (tld) => { const domainRegistration: WithSources = { ...baseDomainRegistrationFields, tld: tld as unknown as 'xyo' } - expect(domainRegistrationTldValidator(domainRegistration)).toBe(false) + expect(domainTldValidator(domainRegistration)).toBe(false) }) }) }) @@ -97,14 +97,14 @@ describe('XNS Name Validators', () => { describe('Valid', () => { it.each(valid)('should return true for %s', (domain) => { const domainRegistration: WithSources = { ...baseDomainRegistrationFields, domain } - expect(getDomainRegistrationLengthValidator(minNameLength)(domainRegistration)).toBe(true) + expect(getDomainLengthValidator(minNameLength)(domainRegistration)).toBe(true) }) }) describe('Invalid', () => { it.each(invalid)('should return false for %s', (domain) => { const domainRegistration: WithSources = { ...baseDomainRegistrationFields, domain } - expect(getDomainRegistrationLengthValidator(minNameLength)(domainRegistration)).toBe(false) + expect(getDomainLengthValidator(minNameLength)(domainRegistration)).toBe(false) }) }) }) @@ -139,7 +139,7 @@ describe('XNS Name Validators', () => { describe.each(casesHyphens)('$name with $options', ({ options, valid, invalid, }) => { - const validator = getDomainRegistrationAllowedHyphensValidator(options) + const validator = getDomainAllowedHyphensValidator(options) describe('Valid', () => { it.each(valid)('should return true for %s', (domain) => { const domainRegistration: WithSources = { ...baseDomainRegistrationFields, domain } diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/validators.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/validators.ts index 7222ab52c..c506513ca 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/validators.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/validators.ts @@ -1,11 +1,11 @@ import { isModuleName } from '@xyo-network/module-model' -import type { PayloadValidationFunction, WithSources } from '@xyo-network/payload-model' -import type { Domain } from '@xyo-network/xns-record-payload-plugins' +import type { Payload, PayloadValidationFunction } from '@xyo-network/payload-model' +import type { DomainFields } from '@xyo-network/xns-record-payload-plugins' -export const domainRegistrationCasingValidator: PayloadValidationFunction> = ( - domainRegistration: WithSources, +export const domainCasingValidator: PayloadValidationFunction> = ( + payload: Payload, ) => { - const { domain } = domainRegistration + const { domain } = payload // Check if all lowercase if (domain.toLowerCase() !== domain) { console.log('name must be lowercase') @@ -14,10 +14,10 @@ export const domainRegistrationCasingValidator: PayloadValidationFunction> = ( - domainRegistration: WithSources, +export const domainModuleNameValidator: PayloadValidationFunction> = ( + payload: Payload, ) => { - const { domain } = domainRegistration + const { domain } = payload // check if domain is a valid name if (!isModuleName(domain)) { @@ -28,10 +28,10 @@ export const domainRegistrationModuleNameValidator: PayloadValidationFunction> = ( - domainRegistration: WithSources, +export const domainTldValidator: PayloadValidationFunction> = ( + payload: Payload, ) => { - const { tld } = domainRegistration + const { tld } = payload // Check if all lowercase if (tld.toLowerCase() !== tld) { console.log('TLD must be lowercase') @@ -45,9 +45,9 @@ export const domainRegistrationTldValidator: PayloadValidationFunction> => { - return (domainRegistration: WithSources) => { - const { domain } = domainRegistration +export const getDomainLengthValidator = (minNameLength = 3): PayloadValidationFunction> => { + return (payload: Payload) => { + const { domain } = payload // Check if min length if (domain.length < minNameLength) { console.log(`name must be at least ${minNameLength} characters`) @@ -57,11 +57,11 @@ export const getDomainRegistrationLengthValidator = (minNameLength = 3): Payload } } -export const getDomainRegistrationAllowedHyphensValidator = ( +export const getDomainAllowedHyphensValidator = ( options?: { end?: boolean; start?: boolean }, -): PayloadValidationFunction> => { - return (domainRegistration: WithSources) => { - const { domain } = domainRegistration +): PayloadValidationFunction> => { + return (payload: Payload) => { + const { domain } = payload const { start, end } = options ?? {} if (!start && domain.startsWith('-')) { console.log('name cannot start with hyphen') @@ -76,9 +76,9 @@ export const getDomainRegistrationAllowedHyphensValidator = ( } export const XnsNamePublicValidators = [ - domainRegistrationCasingValidator, - domainRegistrationModuleNameValidator, - domainRegistrationTldValidator, - getDomainRegistrationLengthValidator(), - getDomainRegistrationAllowedHyphensValidator(), + domainCasingValidator, + domainModuleNameValidator, + domainTldValidator, + getDomainLengthValidator(), + getDomainAllowedHyphensValidator(), ] From ce5d6081c2ffc1b19e19232986829a4651f56a3c Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Wed, 4 Sep 2024 11:33:05 -0500 Subject: [PATCH 32/46] Update yarn scripts --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index c0c1d8fd3..55704053a 100644 --- a/package.json +++ b/package.json @@ -38,8 +38,7 @@ "coverage": "yarn jest --coverage --forceExit", "deploy": "xy deploy", "lint-pkg": "npmPkgJsonLint .", - "test": "jest --no-cache --forceExit", - "test-esm": "node $(yarn jest --no-cache --forceExit)" + "test": "vitest run" }, "resolutions": { "axios": "^1", From 339bb9f0fe074d8d60c1df5f9e25bc2d4b120b5d Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Wed, 4 Sep 2024 11:34:27 -0500 Subject: [PATCH 33/46] Update method names in tests --- .../validation/factory/spec/validators.spec.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/validation/factory/spec/validators.spec.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/factory/spec/validators.spec.ts index 6b2bca9a3..962c8c738 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/validation/validation/factory/spec/validators.spec.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/factory/spec/validators.spec.ts @@ -3,7 +3,7 @@ import type { DomainRegistration } from '@xyo-network/xns-record-payload-plugins import { DomainRegistrationSchema } from '@xyo-network/xns-record-payload-plugins' import { - getDomainRegistrationReservedFragmentsValidator, getDomainRegistrationReservedNamesValidator, getDomainRegistrationReservedStringsValidator, + getDomainReservedFragmentsValidator, getDomainReservedNamesValidator, getDomainReservedStringsValidator, } from '../index.ts' const baseDomainRegistrationFields: DomainRegistration = { @@ -18,42 +18,42 @@ describe('XNS Name Validators', () => { describe('Private Validators', () => { const cases = [ { - getValidator: getDomainRegistrationReservedStringsValidator, + getValidator: getDomainReservedStringsValidator, name: 'ReservedStringsValidator', reservedList: ['foo'], valid: ['bar'], invalid: ['foo'], }, { - getValidator: getDomainRegistrationReservedStringsValidator, + getValidator: getDomainReservedStringsValidator, name: 'ReservedStringsValidator', reservedList: [], valid: ['bar', 'foobar'], invalid: [''], }, { - getValidator: getDomainRegistrationReservedFragmentsValidator, + getValidator: getDomainReservedFragmentsValidator, name: 'ReservedFragmentsValidator', reservedList: ['foo'], valid: ['bar'], invalid: ['foobar', 'bar-foo'], }, { - getValidator: getDomainRegistrationReservedFragmentsValidator, + getValidator: getDomainReservedFragmentsValidator, name: 'ReservedFragmentsValidator', reservedList: [], valid: ['foobar', 'bar-foo'], invalid: [''], }, { - getValidator: getDomainRegistrationReservedNamesValidator, + getValidator: getDomainReservedNamesValidator, name: 'ReservedNamesValidator', reservedList: ['john doe'], valid: ['john1'], invalid: ['johndoe', 'doejohn'], }, { - getValidator: getDomainRegistrationReservedNamesValidator, + getValidator: getDomainReservedNamesValidator, name: 'ReservedNamesValidator', reservedList: [], valid: ['john', 'doe'], From 6154583682f2f8b60879ac025525a7c6110e021b Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Wed, 4 Sep 2024 11:39:51 -0500 Subject: [PATCH 34/46] Simplify type imports --- .../record/src/validation/name/Name.ts | 12 ++++------ .../factory/spec/validators.spec.ts | 22 +++++++------------ .../validation/factory/validators.ts | 12 +++++----- 3 files changed, 18 insertions(+), 28 deletions(-) diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts index 39bb68e11..44834c153 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts @@ -3,11 +3,7 @@ import { isHash } from '@xylabs/hex' import type { Promisable } from '@xylabs/promise' import { DisallowedModuleIdentifierCharacters } from '@xyo-network/module-model' import type { Payload } from '@xyo-network/payload-model' -import type { - Domain, - DomainFields, - TopLevelDomain, -} from '@xyo-network/xns-record-payload-plugins' +import type { DomainFields, TopLevelDomain } from '@xyo-network/xns-record-payload-plugins' import { DomainSchema } from '@xyo-network/xns-record-payload-plugins' import { XnsNamePublicValidators } from '../validation/index.ts' @@ -50,7 +46,7 @@ export class XnsNameHelper { } /** - * Create an XnsNameHelper from a domain registration payload + * Create an XnsNameHelper from a domain payload * @param {Domain} domain * @returns Promise */ @@ -85,8 +81,8 @@ export class XnsNameHelper { return xnsName ? 'xnsName' : null } - static isValid(domainRegistration: Domain) { - return XnsNamePublicValidators.every(validator => validator(domainRegistration)) + static isValid(domain: Payload) { + return XnsNamePublicValidators.every(validator => validator(domain)) } /** diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/validation/factory/spec/validators.spec.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/factory/spec/validators.spec.ts index 962c8c738..aefc13c87 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/validation/validation/factory/spec/validators.spec.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/factory/spec/validators.spec.ts @@ -1,16 +1,13 @@ -import type { WithSources } from '@xyo-network/payload-model' -import type { DomainRegistration } from '@xyo-network/xns-record-payload-plugins' -import { DomainRegistrationSchema } from '@xyo-network/xns-record-payload-plugins' +import type { Domain } from '@xyo-network/xns-record-payload-plugins' +import { DomainSchema } from '@xyo-network/xns-record-payload-plugins' import { getDomainReservedFragmentsValidator, getDomainReservedNamesValidator, getDomainReservedStringsValidator, } from '../index.ts' -const baseDomainRegistrationFields: DomainRegistration = { +const baseDomainFields: Domain = { domain: '', - registrant: [], - registrar: [], - schema: DomainRegistrationSchema, + schema: DomainSchema, tld: 'xyo', } @@ -67,18 +64,15 @@ describe('XNS Name Validators', () => { const validator = getValidator(reservedList) describe('Valid', () => { it.each(valid)('should return true for %s', (domain) => { - const domainRegistration: WithSources = { ...baseDomainRegistrationFields, domain } - expect(validator(domainRegistration)).toBe(true) + const payload: Domain = { ...baseDomainFields, domain } + expect(validator(payload)).toBe(true) }) }) - describe('Invalid', () => { it.each(invalid)('should return false for %s', (domain) => { if (domain) { - const domainRegistration: WithSources = { ...baseDomainRegistrationFields, domain } - expect(validator(domainRegistration)).toBe(false) - } else { - expect(true).toBe(true) + const payload: Domain = { ...baseDomainFields, domain } + expect(validator(payload)).toBe(false) } }) }) diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/validation/factory/validators.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/factory/validators.ts index 401ada572..542e79a8b 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/validation/validation/factory/validators.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/factory/validators.ts @@ -4,8 +4,8 @@ import type { DomainFields } from '@xyo-network/xns-record-payload-plugins' export const getDomainReservedStringsValidator = ( reservedStrings: string[], ): PayloadValidationFunction> => { - return (domainRegistration: Payload) => { - const { domain } = domainRegistration + return (payload: Payload) => { + const { domain } = payload // Check if in one of the reserved name lists if (reservedStrings.includes(domain)) { console.log('Reserved name') @@ -18,8 +18,8 @@ export const getDomainReservedStringsValidator = ( export const getDomainReservedFragmentsValidator = ( reservedFragments: string[], ): PayloadValidationFunction> => { - return (domainRegistration: Payload) => { - const { domain } = domainRegistration + return (payload: Payload) => { + const { domain } = payload // Check if any of our fragments are in the name for (const reserved of reservedFragments) { if (domain.includes(reserved)) { @@ -32,8 +32,8 @@ export const getDomainReservedFragmentsValidator = ( } export const getDomainReservedNamesValidator = (reservedNames: string[]): PayloadValidationFunction> => { - return (domainRegistration: Payload) => { - const { domain } = domainRegistration + return (payload: Payload) => { + const { domain } = payload // Check if any of our fragments are in the name for (const reserved of reservedNames) { const parts = reserved.split(' ') From 231fc9a3a4ffcaa8baadfa89b85aa255257ee584 Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Wed, 4 Sep 2024 11:46:33 -0500 Subject: [PATCH 35/46] Update tests to use domains --- .../validators/spec/validators.spec.ts | 59 +++++++++---------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/spec/validators.spec.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/spec/validators.spec.ts index 0074bd753..02efcfc7b 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/spec/validators.spec.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/spec/validators.spec.ts @@ -3,9 +3,8 @@ * and require no special access to private data. */ -import type { WithSources } from '@xyo-network/payload-model' -import type { DomainRegistration } from '@xyo-network/xns-record-payload-plugins' -import { DomainRegistrationSchema } from '@xyo-network/xns-record-payload-plugins' +import type { Domain } from '@xyo-network/xns-record-payload-plugins' +import { DomainSchema } from '@xyo-network/xns-record-payload-plugins' import { domainCasingValidator, @@ -15,11 +14,9 @@ import { getDomainLengthValidator, } from '../index.ts' -const baseDomainRegistrationFields: DomainRegistration = { +const baseDomainFields: Domain = { domain: '', - registrant: [], - registrar: [], - schema: DomainRegistrationSchema, + schema: DomainSchema, tld: 'xyo', } @@ -27,13 +24,13 @@ describe('XNS Name Validators', () => { describe('Public Validators', () => { const cases = [ { - name: 'domainRegistrationCasingValidator', + name: 'domainCasingValidator', validator: domainCasingValidator, valid: ['example'], invalid: ['Example'], }, { - name: 'domainRegistrationModuleNameValidator', + name: 'domainModuleNameValidator', validator: domainModuleNameValidator, valid: ['valid-domain'], invalid: ['invalid_domain'], @@ -45,22 +42,22 @@ describe('XNS Name Validators', () => { }) => { describe('Valid', () => { it.each(valid)('should return true for %s', (domain) => { - const domainRegistration: WithSources = { ...baseDomainRegistrationFields, domain } - expect(validator(domainRegistration)).toBe(true) + const payload: Domain = { ...baseDomainFields, domain } + expect(validator(payload)).toBe(true) }) }) describe('Invalid', () => { it.each(invalid)('should return false for %s', (domain) => { - const domainRegistration: WithSources = { ...baseDomainRegistrationFields, domain } - expect(validator(domainRegistration)).toBe(false) + const payload: Domain = { ...baseDomainFields, domain } + expect(validator(payload)).toBe(false) }) }) }) const casesTld = [ { - name: 'domainRegistrationTldValidator', + name: 'domainTldValidator', valid: ['xyo'], invalid: ['com', 'Xyo'], }, @@ -69,22 +66,22 @@ describe('XNS Name Validators', () => { describe.each(casesTld)('$name', ({ valid, invalid }) => { describe('Valid', () => { it.each(valid)('should return true for %s', (tld) => { - const domainRegistration: WithSources = { ...baseDomainRegistrationFields, tld: tld as unknown as 'xyo' } - expect(domainTldValidator(domainRegistration)).toBe(true) + const payload: Domain = { ...baseDomainFields, tld: tld as unknown as 'xyo' } + expect(domainTldValidator(payload)).toBe(true) }) }) describe('Invalid', () => { it.each(invalid)('should return false for %s', (tld) => { - const domainRegistration: WithSources = { ...baseDomainRegistrationFields, tld: tld as unknown as 'xyo' } - expect(domainTldValidator(domainRegistration)).toBe(false) + const payload: Domain = { ...baseDomainFields, tld: tld as unknown as 'xyo' } + expect(domainTldValidator(payload)).toBe(false) }) }) }) const casesLength = [ { - name: 'getDomainRegistrationLengthValidator', + name: 'getDomainLengthValidator', minNameLength: 3, valid: ['abc', 'abcd'], invalid: ['', 'a'], @@ -96,40 +93,40 @@ describe('XNS Name Validators', () => { }) => { describe('Valid', () => { it.each(valid)('should return true for %s', (domain) => { - const domainRegistration: WithSources = { ...baseDomainRegistrationFields, domain } - expect(getDomainLengthValidator(minNameLength)(domainRegistration)).toBe(true) + const payload: Domain = { ...baseDomainFields, domain } + expect(getDomainLengthValidator(minNameLength)(payload)).toBe(true) }) }) describe('Invalid', () => { it.each(invalid)('should return false for %s', (domain) => { - const domainRegistration: WithSources = { ...baseDomainRegistrationFields, domain } - expect(getDomainLengthValidator(minNameLength)(domainRegistration)).toBe(false) + const payload: Domain = { ...baseDomainFields, domain } + expect(getDomainLengthValidator(minNameLength)(payload)).toBe(false) }) }) }) const casesHyphens = [ { - name: 'getDomainRegistrationAllowedHyphensValidator', + name: 'getDomainAllowedHyphensValidator', options: {}, valid: ['example'], invalid: ['example-', '-example', '-example-'], }, { - name: 'getDomainRegistrationAllowedHyphensValidator', + name: 'getDomainAllowedHyphensValidator', options: { start: true }, valid: ['example', '-example'], invalid: ['example-', '-example-'], }, { - name: 'getDomainRegistrationAllowedHyphensValidator', + name: 'getDomainAllowedHyphensValidator', options: { end: true }, valid: ['example', 'example-'], invalid: ['-example', '-example-'], }, { - name: 'getDomainRegistrationAllowedHyphensValidator', + name: 'getDomainAllowedHyphensValidator', options: { start: true, end: true }, valid: ['example', '-example', 'example-', '-example-'], invalid: [''], @@ -142,16 +139,16 @@ describe('XNS Name Validators', () => { const validator = getDomainAllowedHyphensValidator(options) describe('Valid', () => { it.each(valid)('should return true for %s', (domain) => { - const domainRegistration: WithSources = { ...baseDomainRegistrationFields, domain } - expect(validator(domainRegistration)).toBe(true) + const payload: Domain = { ...baseDomainFields, domain } + expect(validator(payload)).toBe(true) }) }) describe('Invalid', () => { it.each(invalid)('should return false for %s', (domain) => { if (domain) { - const domainRegistration: WithSources = { ...baseDomainRegistrationFields, domain } - expect(validator(domainRegistration)).toBe(false) + const payload: Domain = { ...baseDomainFields, domain } + expect(validator(payload)).toBe(false) } else { return true } From 35fe32a5fad2b9348cf9094be8952bfe8912962c Mon Sep 17 00:00:00 2001 From: Matt Jones <885417+jonesmac@users.noreply.github.com> Date: Wed, 4 Sep 2024 13:36:51 -0400 Subject: [PATCH 36/46] extract one off code to /lib and types to /types --- .../xns/plugins/record/src/validation/index.ts | 1 + .../plugins/record/src/validation/name/Name.ts | 15 ++------------- .../plugins/record/src/validation/name/index.ts | 2 ++ .../src/validation/name/lib/RegexHelpers.ts | 12 ++++++++++++ .../record/src/validation/name/lib/index.ts | 1 + .../src/validation/name/types/ValidSources.ts | 1 + .../record/src/validation/name/types/index.ts | 1 + 7 files changed, 20 insertions(+), 13 deletions(-) create mode 100644 packages/payloadset/packages/xns/plugins/record/src/validation/name/index.ts create mode 100644 packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/RegexHelpers.ts create mode 100644 packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/index.ts create mode 100644 packages/payloadset/packages/xns/plugins/record/src/validation/name/types/ValidSources.ts create mode 100644 packages/payloadset/packages/xns/plugins/record/src/validation/name/types/index.ts diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/index.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/index.ts index 1ba6af44c..cbf4b2a86 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/validation/index.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/index.ts @@ -1 +1,2 @@ +export * from './name/index.ts' export * from './validation/index.ts' diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts index 44834c153..ff17469ea 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts @@ -1,24 +1,13 @@ import { assertEx } from '@xylabs/assert' import { isHash } from '@xylabs/hex' import type { Promisable } from '@xylabs/promise' -import { DisallowedModuleIdentifierCharacters } from '@xyo-network/module-model' import type { Payload } from '@xyo-network/payload-model' import type { DomainFields, TopLevelDomain } from '@xyo-network/xns-record-payload-plugins' import { DomainSchema } from '@xyo-network/xns-record-payload-plugins' import { XnsNamePublicValidators } from '../validation/index.ts' - -export type ValidSourceTypes = 'xnsName' | 'hash' | null - -// Escaping special regex characters in the disallowed keys -const escapeRegex = (str: string) => str.replaceAll(/[$()*+.?[\\\]^{|}]/g, String.raw`\$&`) - -// Escaping and then creating the regex -const disallowedCharsPattern = Object.keys(DisallowedModuleIdentifierCharacters) - .map(escapeRegex) - .join('') -// Creating the final regex -const REMOVE_DISALLOWED_CHARS = new RegExp(`[${disallowedCharsPattern}]`, 'g') +import { REMOVE_DISALLOWED_CHARS } from './lib/index.ts' +import type { ValidSourceTypes } from './types/index.ts' export class XnsNameHelper { static ValidTLDs = ['.xyo'] as const diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/name/index.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/name/index.ts new file mode 100644 index 000000000..df431fb1d --- /dev/null +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/name/index.ts @@ -0,0 +1,2 @@ +export * from './Name.ts' +export * from './types/index.ts' diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/RegexHelpers.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/RegexHelpers.ts new file mode 100644 index 000000000..eecc10619 --- /dev/null +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/RegexHelpers.ts @@ -0,0 +1,12 @@ +import { DisallowedModuleIdentifierCharacters } from '@xyo-network/module-model' + +// Escaping special regex characters in the disallowed keys +export const escapeRegex = (str: string) => str.replaceAll(/[$()*+.?[\\\]^{|}]/g, String.raw`\$&`) + +// Escaping and then creating the regex +export const disallowedCharsPattern = Object.keys(DisallowedModuleIdentifierCharacters) + .map(escapeRegex) + .join('') + +// Creating the final regex +export const REMOVE_DISALLOWED_CHARS = new RegExp(`[${disallowedCharsPattern}]`, 'g') diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/index.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/index.ts new file mode 100644 index 000000000..06ec6c94f --- /dev/null +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/index.ts @@ -0,0 +1 @@ +export * from './RegexHelpers.ts' diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/name/types/ValidSources.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/name/types/ValidSources.ts new file mode 100644 index 000000000..f969aff60 --- /dev/null +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/name/types/ValidSources.ts @@ -0,0 +1 @@ +export type ValidSourceTypes = 'xnsName' | 'hash' | null diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/name/types/index.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/name/types/index.ts new file mode 100644 index 000000000..eed3d7d98 --- /dev/null +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/name/types/index.ts @@ -0,0 +1 @@ +export * from './ValidSources.ts' From c7ad1456cf739bb2ff6020f3056183aa66c01f3a Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Wed, 4 Sep 2024 12:50:39 -0500 Subject: [PATCH 37/46] remove regex solution for simplicity --- .../xns/plugins/record/src/validation/name/Name.ts | 6 ++++-- .../record/src/validation/name/lib/RegexHelpers.ts | 12 ------------ .../plugins/record/src/validation/name/lib/index.ts | 1 - 3 files changed, 4 insertions(+), 15 deletions(-) delete mode 100644 packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/RegexHelpers.ts delete mode 100644 packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/index.ts diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts index ff17469ea..64563ba6b 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts @@ -1,12 +1,12 @@ import { assertEx } from '@xylabs/assert' import { isHash } from '@xylabs/hex' import type { Promisable } from '@xylabs/promise' +import { DisallowedModuleIdentifierCharacters } from '@xyo-network/module-model' import type { Payload } from '@xyo-network/payload-model' import type { DomainFields, TopLevelDomain } from '@xyo-network/xns-record-payload-plugins' import { DomainSchema } from '@xyo-network/xns-record-payload-plugins' import { XnsNamePublicValidators } from '../validation/index.ts' -import { REMOVE_DISALLOWED_CHARS } from './lib/index.ts' import type { ValidSourceTypes } from './types/index.ts' export class XnsNameHelper { @@ -91,7 +91,9 @@ export class XnsNameHelper { // Filter out disallowed characters. // NOTE: not necessary because of the regex/replacement above, but leaving for when certain special characters become allowed - formattedXnsName = formattedXnsName.replaceAll(REMOVE_DISALLOWED_CHARS, '') + for (const reservedCharacter in DisallowedModuleIdentifierCharacters) { + formattedXnsName = formattedXnsName.replaceAll(reservedCharacter, '') + } return formattedXnsName } diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/RegexHelpers.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/RegexHelpers.ts deleted file mode 100644 index eecc10619..000000000 --- a/packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/RegexHelpers.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { DisallowedModuleIdentifierCharacters } from '@xyo-network/module-model' - -// Escaping special regex characters in the disallowed keys -export const escapeRegex = (str: string) => str.replaceAll(/[$()*+.?[\\\]^{|}]/g, String.raw`\$&`) - -// Escaping and then creating the regex -export const disallowedCharsPattern = Object.keys(DisallowedModuleIdentifierCharacters) - .map(escapeRegex) - .join('') - -// Creating the final regex -export const REMOVE_DISALLOWED_CHARS = new RegExp(`[${disallowedCharsPattern}]`, 'g') diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/index.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/index.ts deleted file mode 100644 index 06ec6c94f..000000000 --- a/packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './RegexHelpers.ts' From a969ff2bcf86bdd3eced3c87c2d2756fbbd83b9a Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Wed, 4 Sep 2024 12:55:37 -0500 Subject: [PATCH 38/46] Remove for loop in favor of single pass using Set --- .../plugins/record/src/validation/name/Name.ts | 8 ++------ .../record/src/validation/name/lib/index.ts | 1 + .../name/lib/removeDisallowedCharacters.ts | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/index.ts create mode 100644 packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/removeDisallowedCharacters.ts diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts index 64563ba6b..76a3b1f00 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts @@ -7,6 +7,7 @@ import type { DomainFields, TopLevelDomain } from '@xyo-network/xns-record-paylo import { DomainSchema } from '@xyo-network/xns-record-payload-plugins' import { XnsNamePublicValidators } from '../validation/index.ts' +import { removeDisallowedCharacters } from './lib/index.ts' import type { ValidSourceTypes } from './types/index.ts' export class XnsNameHelper { @@ -90,11 +91,6 @@ export class XnsNameHelper { formattedXnsName = formattedXnsName.replaceAll(/^-+|-+$/g, '') // Filter out disallowed characters. - // NOTE: not necessary because of the regex/replacement above, but leaving for when certain special characters become allowed - for (const reservedCharacter in DisallowedModuleIdentifierCharacters) { - formattedXnsName = formattedXnsName.replaceAll(reservedCharacter, '') - } - - return formattedXnsName + return removeDisallowedCharacters(formattedXnsName) } } diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/index.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/index.ts new file mode 100644 index 000000000..f15734e49 --- /dev/null +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/index.ts @@ -0,0 +1 @@ +export * from './removeDisallowedCharacters.ts' diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/removeDisallowedCharacters.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/removeDisallowedCharacters.ts new file mode 100644 index 000000000..02ea52959 --- /dev/null +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/removeDisallowedCharacters.ts @@ -0,0 +1,18 @@ +import { DisallowedModuleIdentifierCharacters } from '@xyo-network/module-model' + +const DISALLOWED_CHARACTERS = new Set(Object.keys(DisallowedModuleIdentifierCharacters)) + +/** + * Iterates over a string removing disallowed characters + * @param xnsName The XNS name to remove disallowed characters from + * @returns The XNS name with disallowed characters removed + */ +export const removeDisallowedCharacters = (xnsName: string): string => { + let result = '' + for (const char of xnsName) { + if (!DISALLOWED_CHARACTERS.has(char)) { + result += char + } + } + return result +} From a7cdcd7d939b15a003c9736c8e39621d0e98db3f Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Wed, 4 Sep 2024 12:58:36 -0500 Subject: [PATCH 39/46] Comments for internal data types --- .../src/validation/name/lib/removeDisallowedCharacters.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/removeDisallowedCharacters.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/removeDisallowedCharacters.ts index 02ea52959..3b896599f 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/removeDisallowedCharacters.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/removeDisallowedCharacters.ts @@ -1,5 +1,8 @@ import { DisallowedModuleIdentifierCharacters } from '@xyo-network/module-model' +/** + * A set of all the disallowed characters in module identifiers + */ const DISALLOWED_CHARACTERS = new Set(Object.keys(DisallowedModuleIdentifierCharacters)) /** @@ -8,11 +11,16 @@ const DISALLOWED_CHARACTERS = new Set(Object.keys(DisallowedModuleIdentifierChar * @returns The XNS name with disallowed characters removed */ export const removeDisallowedCharacters = (xnsName: string): string => { + // Create the initial result let result = '' + // Iterate over each character in the XNS name for (const char of xnsName) { + // If the character is not a disallowed character if (!DISALLOWED_CHARACTERS.has(char)) { + // add it to the result result += char } } + // Return the result which contains only allowed characters return result } From d72e7013eece26ad257bd8c89db14e8bbcc4f19f Mon Sep 17 00:00:00 2001 From: Matt Jones <885417+jonesmac@users.noreply.github.com> Date: Wed, 4 Sep 2024 13:59:10 -0400 Subject: [PATCH 40/46] clean up imports --- .../packages/xns/plugins/record/src/validation/name/Name.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts index 76a3b1f00..cd7bc2944 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts @@ -1,7 +1,6 @@ import { assertEx } from '@xylabs/assert' import { isHash } from '@xylabs/hex' import type { Promisable } from '@xylabs/promise' -import { DisallowedModuleIdentifierCharacters } from '@xyo-network/module-model' import type { Payload } from '@xyo-network/payload-model' import type { DomainFields, TopLevelDomain } from '@xyo-network/xns-record-payload-plugins' import { DomainSchema } from '@xyo-network/xns-record-payload-plugins' From 2324692c28f9858e76eff03708018d350bd98b25 Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Wed, 4 Sep 2024 13:31:02 -0500 Subject: [PATCH 41/46] Remove unused import --- .../packages/xns/plugins/record/src/validation/name/Name.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts index 76a3b1f00..cd7bc2944 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts @@ -1,7 +1,6 @@ import { assertEx } from '@xylabs/assert' import { isHash } from '@xylabs/hex' import type { Promisable } from '@xylabs/promise' -import { DisallowedModuleIdentifierCharacters } from '@xyo-network/module-model' import type { Payload } from '@xyo-network/payload-model' import type { DomainFields, TopLevelDomain } from '@xyo-network/xns-record-payload-plugins' import { DomainSchema } from '@xyo-network/xns-record-payload-plugins' From 221c1629d91d2933887e4a0dc2de850a63ee1db0 Mon Sep 17 00:00:00 2001 From: Matt Jones <885417+jonesmac@users.noreply.github.com> Date: Wed, 4 Sep 2024 15:19:59 -0400 Subject: [PATCH 42/46] Rename exported validator set --- .../packages/xns/plugins/record/src/validation/name/Name.ts | 4 ++-- .../record/src/validation/validation/validators/validators.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts index cd7bc2944..e07542907 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts @@ -5,7 +5,7 @@ import type { Payload } from '@xyo-network/payload-model' import type { DomainFields, TopLevelDomain } from '@xyo-network/xns-record-payload-plugins' import { DomainSchema } from '@xyo-network/xns-record-payload-plugins' -import { XnsNamePublicValidators } from '../validation/index.ts' +import { XnsNameSimpleValidators } from '../validation/index.ts' import { removeDisallowedCharacters } from './lib/index.ts' import type { ValidSourceTypes } from './types/index.ts' @@ -71,7 +71,7 @@ export class XnsNameHelper { } static isValid(domain: Payload) { - return XnsNamePublicValidators.every(validator => validator(domain)) + return XnsNameSimpleValidators.every(validator => validator(domain)) } /** diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/validators.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/validators.ts index c506513ca..d0beae1b4 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/validators.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/validators.ts @@ -75,7 +75,7 @@ export const getDomainAllowedHyphensValidator = ( } } -export const XnsNamePublicValidators = [ +export const XnsNameSimpleValidators = [ domainCasingValidator, domainModuleNameValidator, domainTldValidator, From 86e37469967774359ef2383386b31bd6c21a6b83 Mon Sep 17 00:00:00 2001 From: Matt Jones <885417+jonesmac@users.noreply.github.com> Date: Wed, 4 Sep 2024 15:20:16 -0400 Subject: [PATCH 43/46] validate max length --- .../record/src/validation/validation/Constants.ts | 2 ++ .../plugins/record/src/validation/validation/index.ts | 1 + .../validation/validation/validators/validators.ts | 11 ++++++++++- 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 packages/payloadset/packages/xns/plugins/record/src/validation/validation/Constants.ts diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/validation/Constants.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/Constants.ts new file mode 100644 index 000000000..5cfb6509a --- /dev/null +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/Constants.ts @@ -0,0 +1,2 @@ +export const MIN_DOMAIN_LENGTH = 3 +export const MAX_DOMAIN_LENGTH = 128 diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/validation/index.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/index.ts index c5e28003f..2313653f3 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/validation/validation/index.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/index.ts @@ -1,2 +1,3 @@ +export * from './Constants.ts' export * from './factory/index.ts' export * from './validators/index.ts' diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/validators.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/validators.ts index d0beae1b4..3756d3166 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/validators.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/validators.ts @@ -2,6 +2,8 @@ import { isModuleName } from '@xyo-network/module-model' import type { Payload, PayloadValidationFunction } from '@xyo-network/payload-model' import type { DomainFields } from '@xyo-network/xns-record-payload-plugins' +import { MAX_DOMAIN_LENGTH, MIN_DOMAIN_LENGTH } from '../Constants.ts' + export const domainCasingValidator: PayloadValidationFunction> = ( payload: Payload, ) => { @@ -45,7 +47,10 @@ export const domainTldValidator: PayloadValidationFunction return true } -export const getDomainLengthValidator = (minNameLength = 3): PayloadValidationFunction> => { +export const getDomainLengthValidator = ( + minNameLength = MIN_DOMAIN_LENGTH, + maxLength = MAX_DOMAIN_LENGTH, +): PayloadValidationFunction> => { return (payload: Payload) => { const { domain } = payload // Check if min length @@ -53,6 +58,10 @@ export const getDomainLengthValidator = (minNameLength = 3): PayloadValidationFu console.log(`name must be at least ${minNameLength} characters`) return false } + if (domain.length > maxLength) { + console.log(`name must be at least ${maxLength} characters`) + return false + } return true } } From 418870b538fd5382fedd258e9d688d149d87bd4c Mon Sep 17 00:00:00 2001 From: Matt Jones <885417+jonesmac@users.noreply.github.com> Date: Wed, 4 Sep 2024 15:22:15 -0400 Subject: [PATCH 44/46] update specs --- .../factory/spec/validators.spec.ts | 4 +-- .../validators/spec/validators.spec.ts | 29 +++++++------------ 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/validation/factory/spec/validators.spec.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/factory/spec/validators.spec.ts index aefc13c87..c1c2faf4e 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/validation/validation/factory/spec/validators.spec.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/factory/spec/validators.spec.ts @@ -11,8 +11,8 @@ const baseDomainFields: Domain = { tld: 'xyo', } -describe('XNS Name Validators', () => { - describe('Private Validators', () => { +describe('XNS Name', () => { + describe('Factory Validators', () => { const cases = [ { getValidator: getDomainReservedStringsValidator, diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/spec/validators.spec.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/spec/validators.spec.ts index 02efcfc7b..f731f0e99 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/spec/validators.spec.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/validation/validators/spec/validators.spec.ts @@ -1,11 +1,7 @@ -/** - * NOTE: These validators are public because they can be validated by clients - * and require no special access to private data. - */ - -import type { Domain } from '@xyo-network/xns-record-payload-plugins' -import { DomainSchema } from '@xyo-network/xns-record-payload-plugins' +import type { Payload } from '@xyo-network/payload-model' +import { type Domain, DomainSchema } from '@xyo-network/xns-record-payload-plugins' +import { MAX_DOMAIN_LENGTH } from '../../Constants.ts' import { domainCasingValidator, domainModuleNameValidator, @@ -14,14 +10,14 @@ import { getDomainLengthValidator, } from '../index.ts' -const baseDomainFields: Domain = { +const baseDomainFields: Payload = { domain: '', - schema: DomainSchema, tld: 'xyo', + schema: DomainSchema, } -describe('XNS Name Validators', () => { - describe('Public Validators', () => { +describe('XNS Name', () => { + describe('Validators', () => { const cases = [ { name: 'domainCasingValidator', @@ -82,26 +78,23 @@ describe('XNS Name Validators', () => { const casesLength = [ { name: 'getDomainLengthValidator', - minNameLength: 3, valid: ['abc', 'abcd'], - invalid: ['', 'a'], + invalid: ['', 'a', 'a'.repeat(MAX_DOMAIN_LENGTH + 1)], }, ] - describe.each(casesLength)('$name', ({ - minNameLength, valid, invalid, - }) => { + describe.each(casesLength)('$name', ({ valid, invalid }) => { describe('Valid', () => { it.each(valid)('should return true for %s', (domain) => { const payload: Domain = { ...baseDomainFields, domain } - expect(getDomainLengthValidator(minNameLength)(payload)).toBe(true) + expect(getDomainLengthValidator()(payload)).toBe(true) }) }) describe('Invalid', () => { it.each(invalid)('should return false for %s', (domain) => { const payload: Domain = { ...baseDomainFields, domain } - expect(getDomainLengthValidator(minNameLength)(payload)).toBe(false) + expect(getDomainLengthValidator()(payload)).toBe(false) }) }) }) From 0306508f796ed54097b0c1e9f665d2731e6f71ab Mon Sep 17 00:00:00 2001 From: Matt Jones <885417+jonesmac@users.noreply.github.com> Date: Wed, 4 Sep 2024 15:36:47 -0400 Subject: [PATCH 45/46] prevent masking from needlessly using regex on large strings --- .../xns/plugins/record/src/validation/name/Name.ts | 7 ++++++- .../plugins/record/src/validation/name/spec/Name.spec.ts | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts index e07542907..d8ee1c744 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts @@ -5,7 +5,7 @@ import type { Payload } from '@xyo-network/payload-model' import type { DomainFields, TopLevelDomain } from '@xyo-network/xns-record-payload-plugins' import { DomainSchema } from '@xyo-network/xns-record-payload-plugins' -import { XnsNameSimpleValidators } from '../validation/index.ts' +import { MAX_DOMAIN_LENGTH, XnsNameSimpleValidators } from '../validation/index.ts' import { removeDisallowedCharacters } from './lib/index.ts' import type { ValidSourceTypes } from './types/index.ts' @@ -80,6 +80,11 @@ export class XnsNameHelper { * @returns string */ static mask(str: string) { + // Check if the domain name is too long + if (str.length > MAX_DOMAIN_LENGTH) { + throw new Error(`Domain name too long: ${str.length} exceeds max length: ${MAX_DOMAIN_LENGTH}`) + } + // convert to lowercase const lowercaseXnsName = str.toLowerCase() diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/name/spec/Name.spec.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/name/spec/Name.spec.ts index 40ce9ac7a..3a418ee48 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/validation/name/spec/Name.spec.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/name/spec/Name.spec.ts @@ -1,6 +1,7 @@ import type { Domain } from '@xyo-network/xns-record-payload-plugins' import { DomainSchema } from '@xyo-network/xns-record-payload-plugins' +import { MAX_DOMAIN_LENGTH } from '../../validation/Constants.ts' import { XnsNameHelper } from '../Name.ts' describe('XnsNameHelper', () => { @@ -113,5 +114,12 @@ describe('XnsNameHelper', () => { expect(XnsNameHelper.mask(input)).toBe(expected) }) }) + + describe('With invalid input', () => { + it('should throw an error', () => { + expect(() => XnsNameHelper.mask('a'.repeat(MAX_DOMAIN_LENGTH + 1))) + .toThrow('Domain name too long: 129 exceeds max length: 128') + }) + }) }) }) From a94e38e2482eada9c29be6c3d12c0038f1e6fab7 Mon Sep 17 00:00:00 2001 From: Matt Jones <885417+jonesmac@users.noreply.github.com> Date: Wed, 4 Sep 2024 15:52:00 -0400 Subject: [PATCH 46/46] lint fix --- .../xns/plugins/record/src/validation/name/spec/Name.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/name/spec/Name.spec.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/name/spec/Name.spec.ts index 3a418ee48..2a37572bb 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/validation/name/spec/Name.spec.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/name/spec/Name.spec.ts @@ -1,7 +1,7 @@ import type { Domain } from '@xyo-network/xns-record-payload-plugins' import { DomainSchema } from '@xyo-network/xns-record-payload-plugins' -import { MAX_DOMAIN_LENGTH } from '../../validation/Constants.ts' +import { MAX_DOMAIN_LENGTH } from '../../validation/index.ts' import { XnsNameHelper } from '../Name.ts' describe('XnsNameHelper', () => {