diff --git a/packages/asset/src/Asset.chain.ts b/packages/asset/src/Asset.chain.ts index 8b63a394..3c5f8cc7 100644 --- a/packages/asset/src/Asset.chain.ts +++ b/packages/asset/src/Asset.chain.ts @@ -43,27 +43,52 @@ export async function isAssetStored(assetUri: AssetUri): Promise { } } -export async function dispatchCreateToChain( +export async function prepareCreateExtrinsic( assetEntry: IAssetEntry, authorAccount: CordKeyringPair, authorizationUri: AuthorizationUri, signCallback: SignExtrinsicCallback -): Promise { +): Promise { try { - const api = ConfigService.get('api') - const authorizationId: AuthorizationId = uriToIdentifier(authorizationUri) + const api = ConfigService.get('api'); + const authorizationId: AuthorizationId = uriToIdentifier(authorizationUri); const tx = api.tx.asset.create( assetEntry.entry, assetEntry.digest, authorizationId - ) + ); const extrinsic = await Did.authorizeTx( assetEntry.creator, tx, signCallback, authorAccount.address + ); + + return extrinsic; + } catch (error) { + const errorMessage = + error instanceof Error ? error.message : JSON.stringify(error); + throw new SDKErrors.CordDispatchError( + `Error preparing extrinsic: "${errorMessage}".` + ); + } +} + +export async function dispatchCreateToChain( + assetEntry: IAssetEntry, + authorAccount: CordKeyringPair, + authorizationUri: AuthorizationUri, + signCallback: SignExtrinsicCallback +): Promise { + try { + + const extrinsic = await prepareCreateExtrinsic( + assetEntry, + authorAccount, + authorizationUri, + signCallback ) await Chain.signAndSubmitTx(extrinsic, authorAccount)