@@ -207,14 +207,13 @@ export default class AssetOperationsManager {
207207 }
208208
209209 /**
210- * Creates a new knowledge collection .
210+ * Phase 1 of asset creation: validate input, build dataset, and publish to the node .
211211 * @async
212- * @param {Object } content - The content of the knowledge collection to be created, contains public, private or both keys.
213- * @param {Object } [options={}] - Additional options for knowledge collection creation.
214- * @param {Object } [stepHooks=emptyHooks] - Hooks to execute during knowledge collection creation.
215- * @returns {Object } Object containing UAL, publicAssertionId and operation status.
212+ * @param {Object|string } content - The content of the knowledge collection.
213+ * @param {Object } [options={}] - Options for knowledge collection creation.
214+ * @returns {Object } Publish phase output including dataset info and publish operation data.
216215 */
217- async create ( content , options = { } , stepHooks = emptyHooks ) {
216+ async publishAssetPhase ( content , options = { } ) {
218217 this . validationService . validateJsonldOrNquads ( content ) ;
219218 const {
220219 blockchain,
@@ -367,17 +366,52 @@ export default class AssetOperationsManager {
367366 publishOperationId ,
368367 ) ;
369368
370- if (
371- publishOperationResult . status !== OPERATION_STATUSES . COMPLETED &&
372- ! publishOperationResult . data . minAcksReached
373- ) {
374- return {
375- datasetRoot,
376- operation : {
377- publish : getOperationStatusObject ( publishOperationResult , publishOperationId ) ,
378- } ,
379- } ;
380- }
369+ return {
370+ dataset,
371+ datasetRoot,
372+ datasetSize,
373+ publishOperationId,
374+ publishOperationResult,
375+ contentAssetStorageAddress,
376+ blockchain,
377+ endpoint,
378+ port,
379+ maxNumberOfRetries,
380+ frequency,
381+ authToken,
382+ epochsNum,
383+ hashFunctionId,
384+ scoreFunctionId,
385+ immutable,
386+ tokenAmount,
387+ payer,
388+ minimumNumberOfFinalizationConfirmations,
389+ minimumNumberOfNodeReplications,
390+ } ;
391+ }
392+
393+ /**
394+ * Phase 2 of asset creation: mint the knowledge collection on chain using publish output.
395+ * @async
396+ * @param {Object } publishPayload - Output of publishAssetPhase.
397+ * @param {Object } [options={}] - Options affecting minting (e.g., minimumBlockConfirmations).
398+ * @param {Object } [stepHooks=emptyHooks] - Hooks to execute during minting.
399+ * @returns {Object } Mint phase output including UAL and mint receipt.
400+ */
401+ async mintKnowledgeCollectionPhase ( publishPayload , options = { } , stepHooks = emptyHooks ) {
402+ const {
403+ dataset,
404+ datasetRoot,
405+ datasetSize,
406+ publishOperationId,
407+ publishOperationResult,
408+ contentAssetStorageAddress,
409+ blockchain,
410+ epochsNum,
411+ immutable,
412+ tokenAmount,
413+ payer,
414+ } = publishPayload ;
381415
382416 const { signatures } = publishOperationResult . data ;
383417
@@ -479,6 +513,45 @@ export default class AssetOperationsManager {
479513
480514 const UAL = deriveUAL ( blockchain . name , contentAssetStorageAddress , knowledgeCollectionId ) ;
481515
516+ return {
517+ UAL ,
518+ knowledgeCollectionId,
519+ mintKnowledgeCollectionReceipt,
520+ datasetRoot,
521+ publishOperationId,
522+ publishOperationResult,
523+ } ;
524+ }
525+
526+ /**
527+ * Phase 3 of asset creation: poll node finality status for the minted asset.
528+ * @async
529+ * @param {string } UAL - Universal Asset Locator returned from minting.
530+ * @param {Object } [options={}] - Finality options.
531+ * @returns {Object } Finality status details.
532+ */
533+ async finalizePublishPhase ( UAL , options = { } ) {
534+ // UAL should point to a knowledge collection (kcUAL), not a knowledge asset (kaUAL).
535+ this . validationService . validateUAL ( UAL ) ;
536+
537+ const {
538+ endpoint,
539+ port,
540+ maxNumberOfRetries,
541+ frequency,
542+ minimumNumberOfFinalizationConfirmations,
543+ authToken,
544+ } = this . inputService . getPublishFinalityArguments ( options ) ;
545+
546+ this . validationService . validatePublishFinality (
547+ endpoint ,
548+ port ,
549+ maxNumberOfRetries ,
550+ frequency ,
551+ minimumNumberOfFinalizationConfirmations ,
552+ authToken ,
553+ ) ;
554+
482555 let finalityStatusResult = 0 ;
483556 if ( minimumNumberOfFinalizationConfirmations > 0 ) {
484557 finalityStatusResult = await this . nodeApiService . finalityStatus (
@@ -493,20 +566,60 @@ export default class AssetOperationsManager {
493566 }
494567
495568 return {
496- UAL ,
497- datasetRoot,
569+ status :
570+ finalityStatusResult >= minimumNumberOfFinalizationConfirmations
571+ ? 'FINALIZED'
572+ : 'NOT FINALIZED' ,
573+ numberOfConfirmations : finalityStatusResult ,
574+ requiredConfirmations : minimumNumberOfFinalizationConfirmations ,
575+ } ;
576+ }
577+
578+ /**
579+ * Creates a new knowledge collection.
580+ * @async
581+ * @param {Object } content - The content of the knowledge collection to be created, contains public, private or both keys.
582+ * @param {Object } [options={}] - Additional options for knowledge collection creation.
583+ * @param {Object } [stepHooks=emptyHooks] - Hooks to execute during knowledge collection creation.
584+ * @returns {Object } Object containing UAL, publicAssertionId and operation status.
585+ */
586+ async create ( content , options = { } , stepHooks = emptyHooks ) {
587+ const publishOperationOutput = await this . publishAssetPhase ( content , options ) ;
588+ const { datasetRoot, publishOperationId, publishOperationResult } = publishOperationOutput ;
589+
590+ if (
591+ publishOperationResult . status !== OPERATION_STATUSES . COMPLETED &&
592+ ! publishOperationResult . data . minAcksReached
593+ ) {
594+ return {
595+ datasetRoot,
596+ operation : {
597+ publish : getOperationStatusObject ( publishOperationResult , publishOperationId ) ,
598+ } ,
599+ } ;
600+ }
601+
602+ const mintOperationOutput = await this . mintKnowledgeCollectionPhase (
603+ publishOperationOutput ,
604+ options ,
605+ stepHooks ,
606+ ) ;
607+
608+ const finalityOperationOutput = await this . finalizePublishPhase (
609+ mintOperationOutput . UAL ,
610+ options ,
611+ ) ;
612+
613+ return {
614+ UAL : mintOperationOutput . UAL ,
615+ datasetRoot : mintOperationOutput . datasetRoot ,
498616 signatures : publishOperationResult . data . signatures ,
499617 operation : {
500- mintKnowledgeCollection : mintKnowledgeCollectionReceipt ,
618+ mintKnowledgeCollection : mintOperationOutput . mintKnowledgeCollectionReceipt ,
501619 publish : getOperationStatusObject ( publishOperationResult , publishOperationId ) ,
502- finality : {
503- status :
504- finalityStatusResult >= minimumNumberOfFinalizationConfirmations
505- ? 'FINALIZED'
506- : 'NOT FINALIZED' ,
507- } ,
508- numberOfConfirmations : finalityStatusResult ,
509- requiredConfirmations : minimumNumberOfFinalizationConfirmations ,
620+ finality : { status : finalityOperationOutput . status } ,
621+ numberOfConfirmations : finalityOperationOutput . numberOfConfirmations ,
622+ requiredConfirmations : finalityOperationOutput . requiredConfirmations ,
510623 } ,
511624 } ;
512625 }
0 commit comments