@@ -5,7 +5,7 @@ import { getCurrentTimeInHighPrecision } from '../../../utils/time.js';
55import { validateAuthorizationIntegrity } from '../../../core/auth.js' ;
66
77import { DwnInterfaceName , DwnMethodName , Message } from '../../../core/message.js' ;
8- import { normalizeProtocolUri , validateProtocolUriNormalized } from '../../../utils/url.js' ;
8+ import { normalizeProtocolUrl , normalizeSchemaUrl , validateProtocolUrlNormalized , validateSchemaUrlNormalized } from '../../../utils/url.js' ;
99
1010export type ProtocolsConfigureOptions = {
1111 dateCreated ? : string ;
@@ -18,7 +18,8 @@ export class ProtocolsConfigure extends Message<ProtocolsConfigureMessage> {
1818
1919 public static async parse ( message : ProtocolsConfigureMessage ) : Promise < ProtocolsConfigure > {
2020 await validateAuthorizationIntegrity ( message ) ;
21- validateProtocolUriNormalized ( message . descriptor . protocol ) ;
21+ validateProtocolUrlNormalized ( message . descriptor . protocol ) ;
22+ ProtocolsConfigure . validateDefinitionNormalized ( message . descriptor . definition ) ;
2223
2324 return new ProtocolsConfigure ( message ) ;
2425 }
@@ -28,8 +29,9 @@ export class ProtocolsConfigure extends Message<ProtocolsConfigureMessage> {
2829 interface : DwnInterfaceName . Protocols ,
2930 method : DwnMethodName . Configure ,
3031 dateCreated : options . dateCreated ?? getCurrentTimeInHighPrecision ( ) ,
31- protocol : normalizeProtocolUri ( options . protocol ) ,
32- definition : options . definition // TODO: #139 - move definition out of the descriptor - https://github.com/TBD54566975/dwn-sdk-js/issues/139
32+ protocol : normalizeProtocolUrl ( options . protocol ) ,
33+ // TODO: #139 - move definition out of the descriptor - https://github.com/TBD54566975/dwn-sdk-js/issues/139
34+ definition : ProtocolsConfigure . normalizeDefinition ( options . definition )
3335 } ;
3436
3537 Message . validateJsonSchema ( { descriptor, authorization : { } } ) ;
@@ -40,4 +42,23 @@ export class ProtocolsConfigure extends Message<ProtocolsConfigureMessage> {
4042 const protocolsConfigure = new ProtocolsConfigure ( message ) ;
4143 return protocolsConfigure ;
4244 }
45+
46+ private static validateDefinitionNormalized ( definition : ProtocolDefinition ) : void {
47+ // validate schema url normalized
48+ for ( const labelKey in definition . labels ) {
49+ const schema = definition . labels [ labelKey ] . schema ;
50+ validateSchemaUrlNormalized ( schema ) ;
51+ }
52+ }
53+
54+ private static normalizeDefinition ( definition : ProtocolDefinition ) : ProtocolDefinition {
55+ const definitionCopy = { ...definition } ;
56+
57+ // Normalize schema url
58+ for ( const labelKey in definition . labels ) {
59+ definitionCopy . labels [ labelKey ] . schema = normalizeSchemaUrl ( definitionCopy . labels [ labelKey ] . schema ) ;
60+ }
61+
62+ return definitionCopy ;
63+ }
4364}
0 commit comments