Skip to content

Commit

Permalink
Add yarn.lock file
Browse files Browse the repository at this point in the history
Signed-off-by: Shreevatsa N <[email protected]>
  • Loading branch information
vatsa287 committed Oct 4, 2024
1 parent 3ed4876 commit 877b85a
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 3 deletions.
17 changes: 14 additions & 3 deletions demo/src/registry-tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,13 @@ async function main() {
colors: true,
})

const delegateAuthorizationUri2 = await Cord.Registries.dispatchDelegateAuthorization(
const delegateAuthorizationUri = await Cord.Registries.dispatchDelegateAuthorization(
registryDelegateAuthProperties,
registry.authorizationUri,
authorIdentity
)

console.log(`\n✅ Registry Authorization added with DELEGATE permission - ${delegateAuthorizationUri2} - added!`)

console.log(`\n✅ Registry Authorization added with DELEGATE permission - ${delegateAuthorizationUri} - added!`)

// Setup a account to be added as a `DELEGATE` delegate.
const { account: adminIdentity } = await createAccount()
Expand Down Expand Up @@ -263,6 +262,18 @@ async function main() {

console.log(`\n✅ Registry Authorization added with ADMIN permission - ${delegateAdminAuthorizationUri} - added!`)

console.log(`\n❄️ Remove Registry Assert Authorization `);

// Remove a delegate with ASSERT permission
const removeAuthObj = await Cord.Registries.dispatchRemoveDelegateToChain(
registry.uri,
delegateAssertAuthorizationUri,
registry.authorizationUri,
authorIdentity
)

console.log(`\n✅ Registry ASSERT Authorization removed - ${delegateAssertAuthorizationUri} - removed!`)

console.log("Balance of Registry Creator after all transactions", await getBalance(authorIdentity.address, api));
}

Expand Down
104 changes: 104 additions & 0 deletions packages/registries/src/Registries.chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -675,3 +675,107 @@ export async function dispatchDelegateAuthorization(
)
}
}


/**
* Removes a delegate from a registry on the chain.
*
* This method is used to remove a delegate's authorization from a given registry. It checks whether the registry
* and the provided authorization exist on-chain, constructs the required parameters, and dispatches the extrinsic
* to the blockchain for execution.
*
* @async
* @function
* @param {RegistryUri} registryUri - The URI of the registry from which the delegate will be removed.
* @param {RegistryAuthorizationUri} removeAuthorizationUri - The URI of the authorization to be removed (i.e., the delegate's authorization).
* @param {RegistryAuthorizationUri} authorizationUri - The URI of the authorization of the account performing the removal (the caller's authorization).
* @param {CordKeyringPair} authorAccount - The account key pair of the entity removing the delegate, used for signing the transaction.
*
* @returns {Promise<{ uri: RegistryUri, removeAuthorizationUri: RegistryAuthorizationUri, authorizationUri: RegistryAuthorizationUri }>}
* An object containing the URIs related to the registry and authorizations.
* - `uri`: The URI of the registry.
* - `removeAuthorizationUri`: The authorization URI of the delegate being removed.
* - `authorizationUri`: The authorization URI of the signer performing the removal.
*
* @throws {SDKErrors.CordDispatchError}
* - If the registry URI does not exist on-chain.
* - If the authorization URI of the signer does not exist on-chain.
* - If an error occurs while dispatching the transaction to the chain.
*
* @example
* ```typescript
* const registryUri = 'did:cord:registry:3abc...';
* const removeAuthorizationUri = 'did:cord:auth:3xyz...';
* const authorizationUri = 'did:cord:auth:3signer...';
* const authorAccount = keyring.addFromUri('//Alice');
*
* dispatchRemoveDelegateToChain(registryUri, removeAuthorizationUri, authorizationUri, authorAccount)
* .then(result => {
* console.log('Delegate removed:', result);
* })
* .catch(error => {
* console.error('Error removing delegate:', error);
* });
* ```
*
* @description
* The function first verifies the existence of the registry and the signer’s authorization on the blockchain.
* It then encodes the provided URIs into identifiers and submits a signed transaction to remove the delegate
* from the registry. If the removal is successful, it returns an object with the registry URI and relevant authorization URIs.
*
*/
export async function dispatchRemoveDelegateToChain(
registryUri: RegistryUri,
removeAuthorizationUri: RegistryAuthorizationUri,
authorizationUri: RegistryAuthorizationUri,
authorAccount: CordKeyringPair,
): Promise<{
uri: RegistryUri,
removeAuthorizationUri: RegistryAuthorizationUri,
authorizationUri: RegistryAuthorizationUri
}> {
const registryObj = {
uri: registryUri,
removeAuthorizationUri: removeAuthorizationUri,
authorizationUri: authorizationUri,
}

const registryExists = await isRegistryStored(registryUri);

if (!registryExists) {
throw new SDKErrors.CordDispatchError(
`Registry URI does not exist: "${registryUri}".`
);
}

const authorizationExists = await isRegistryAuthorizationStored(authorizationUri);
if (!authorizationExists) {
throw new SDKErrors.CordDispatchError(
`Registry remover Authorization URI does not exist: "${authorizationUri}".`
);
}

try {
const api = ConfigService.get('api')

const registryId = uriToIdentifier(registryUri);
const removeAuthorizationId = uriToIdentifier(removeAuthorizationUri);
const authorizationId = uriToIdentifier(authorizationUri);

const extrinsic = api.tx.registries.removeDelegate(
registryId,
removeAuthorizationId,
authorizationId,
);

await Chain.signAndSubmitTx(extrinsic, authorAccount);

return registryObj
} catch(error) {
const errorMessage =
error instanceof Error ? error.message : JSON.stringify(error)
throw new SDKErrors.CordDispatchError(
`Error dispatching to chain: "${errorMessage}".`
)
}
}
15 changes: 15 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1723,6 +1723,20 @@ __metadata:
languageName: unknown
linkType: soft

"@cord.network/registries@workspace:*, @cord.network/registries@workspace:packages/registries":
version: 0.0.0-use.local
resolution: "@cord.network/registries@workspace:packages/registries"
dependencies:
"@cord.network/config": "workspace:*"
"@cord.network/identifier": "workspace:*"
"@cord.network/network": "workspace:*"
"@cord.network/types": "workspace:*"
"@cord.network/utils": "workspace:*"
rimraf: "npm:^5.0.5"
typescript: "npm:^5.3.3"
languageName: unknown
linkType: soft

"@cord.network/schema@workspace:*, @cord.network/schema@workspace:packages/schema":
version: 0.0.0-use.local
resolution: "@cord.network/schema@workspace:packages/schema"
Expand Down Expand Up @@ -1753,6 +1767,7 @@ __metadata:
"@cord.network/identifier": "workspace:*"
"@cord.network/network": "workspace:*"
"@cord.network/network-score": "workspace:*"
"@cord.network/registries": "workspace:*"
"@cord.network/schema": "workspace:*"
"@cord.network/statement": "workspace:*"
"@cord.network/types": "workspace:*"
Expand Down

0 comments on commit 877b85a

Please sign in to comment.