From 104e9434d272c543898e875b8e5f34f5f28d9979 Mon Sep 17 00:00:00 2001 From: Adi Bhagavath Date: Wed, 28 Feb 2024 17:26:22 +0530 Subject: [PATCH 1/3] demo: Add a script to add a network member and create chainspace Signed-off-by: Adi Bhagavath --- demo/src/welcome-developer.ts | 129 ++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 demo/src/welcome-developer.ts diff --git a/demo/src/welcome-developer.ts b/demo/src/welcome-developer.ts new file mode 100644 index 00000000..15ada84c --- /dev/null +++ b/demo/src/welcome-developer.ts @@ -0,0 +1,129 @@ +import * as Cord from "@cord.network/sdk"; +import { createDid } from "../src/utils/generateDid"; +import { + requestJudgement, + setIdentity, + setRegistrar, + provideJudgement, +} from "../src/utils/createRegistrar"; +import { addNetworkMember } from "../src/utils/createAuthorities"; +/** + Adding a Developer to Network + This script facilitates adding a developer as a member of the network. Upon execution, + it provides essential information for developers to start building. + + Command to Run the Script: + npx tsx welcome-developer.ts [] [] + + Input: + networkAddress: Address of the network. + sudoAnchorUri: The sudo anchor URI. + authorAnchorUri (optional): The author anchor URI. (Default value is //Alice) + chainspaceLimit (optional): The chainspace limit. (Default value is 1000) + + Output: + Issuer mnemonic + Issuer DID + Chainspace URI + Chainspace Authorization ID +*/ + +async function main() { + + const networkAddress = process.argv[2]; + const sudoAnchorUri = process.argv[3]; + const authorAnchorUri = process.argv[4] ? process.argv[4] : "//Alice"; + const chainspaceLimit = process.argv[5] ? parseInt(process.argv[5]) : 1000; + + Cord.ConfigService.set({ submitTxResolveOn: Cord.Chain.IS_IN_BLOCK }); + await Cord.connect(networkAddress); + + console.log(`\nCreating the credentials....`) + const authorityAuthorIdentity = Cord.Utils.Crypto.makeKeypairFromUri( + sudoAnchorUri, + "sr25519" + ); + + const authorityIdentity = Cord.Utils.Crypto.makeKeypairFromUri( + "//authority//1", + "ed25519" + ); + + await addNetworkMember(authorityAuthorIdentity, authorityIdentity.address); + await setRegistrar(authorityAuthorIdentity, authorityIdentity.address); + + const authorIdentity = Cord.Utils.Crypto.makeKeypairFromUri( + authorAnchorUri, + "ed25519" + ); + + await addNetworkMember(authorityAuthorIdentity, authorIdentity.address); + await setIdentity(authorIdentity); + await requestJudgement(authorIdentity, authorityIdentity.address); + await provideJudgement(authorityIdentity, authorIdentity.address); + + const { mnemonic: issuerMnemonic, document: issuerDid } = await createDid( + authorIdentity + ); + const issuerKeys = Cord.Utils.Keys.generateKeypairs( + issuerMnemonic, + "ed25519" + ); + + const { mnemonic: delegateTwoMnemonic, document: delegateTwoDid } = + await createDid(authorIdentity); + + const spaceProperties = await Cord.ChainSpace.buildFromProperties( + issuerDid.uri + ); + + const space = await Cord.ChainSpace.dispatchToChain( + spaceProperties, + issuerDid.uri, + authorIdentity, + async ({ data }) => ({ + signature: issuerKeys.authentication.sign(data), + keyType: issuerKeys.authentication.type, + }) + ); + + await Cord.ChainSpace.sudoApproveChainSpace( + authorityAuthorIdentity, + space.uri, + chainspaceLimit + ); + const permission: Cord.PermissionType = Cord.Permission.ASSERT; + const spaceAuthProperties = + await Cord.ChainSpace.buildFromAuthorizationProperties( + space.uri, + delegateTwoDid.uri, + permission, + issuerDid.uri + ); + + const delegateAuth = await Cord.ChainSpace.dispatchDelegateAuthorization( + spaceAuthProperties, + authorIdentity, + space.authorization, + async ({ data }) => ({ + signature: issuerKeys.capabilityDelegation.sign(data), + keyType: issuerKeys.capabilityDelegation.type, + }) + ); + + console.log(`\nThe Author URI:\n${authorAnchorUri}`); + console.log(`\nIssuer mnemonic:\n${issuerMnemonic}`); + console.log(`\nIssuer DID:\n${issuerDid.uri}`); + console.log(`\nThe Chanspace URI:\n${space.uri}`); + console.log(`\nThe chainspace Authorization ID:\n${space.authorization}`); +} + +main() + .then(() => console.log("\nBye! 👋 👋 👋 ")) + .finally(Cord.disconnect); + +process.on("SIGINT", async () => { + console.log("\nBye! 👋 👋 👋 \n"); + Cord.disconnect(); + process.exit(0); +}); \ No newline at end of file From edd4232db29992d83dfe2fc920885371e4accf88 Mon Sep 17 00:00:00 2001 From: Adi Bhagavath Date: Wed, 28 Feb 2024 17:30:38 +0530 Subject: [PATCH 2/3] update: comment --- demo/src/welcome-developer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demo/src/welcome-developer.ts b/demo/src/welcome-developer.ts index 15ada84c..9699ce04 100644 --- a/demo/src/welcome-developer.ts +++ b/demo/src/welcome-developer.ts @@ -8,7 +8,7 @@ import { } from "../src/utils/createRegistrar"; import { addNetworkMember } from "../src/utils/createAuthorities"; /** - Adding a Developer to Network + Adding a Developer to Network and Creating a Chainspace. This script facilitates adding a developer as a member of the network. Upon execution, it provides essential information for developers to start building. From a2be7e7d5a0a9ff6bd9d6b14f69000cd01afc29e Mon Sep 17 00:00:00 2001 From: Adi Bhagavath Date: Thu, 29 Feb 2024 12:23:10 +0530 Subject: [PATCH 3/3] Remove unwanted code Signed-off-by: Adi Bhagavath --- demo/src/welcome-developer.ts | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/demo/src/welcome-developer.ts b/demo/src/welcome-developer.ts index 9699ce04..b7ad2ab6 100644 --- a/demo/src/welcome-developer.ts +++ b/demo/src/welcome-developer.ts @@ -44,23 +44,12 @@ async function main() { "sr25519" ); - const authorityIdentity = Cord.Utils.Crypto.makeKeypairFromUri( - "//authority//1", - "ed25519" - ); - - await addNetworkMember(authorityAuthorIdentity, authorityIdentity.address); - await setRegistrar(authorityAuthorIdentity, authorityIdentity.address); - const authorIdentity = Cord.Utils.Crypto.makeKeypairFromUri( authorAnchorUri, "ed25519" ); await addNetworkMember(authorityAuthorIdentity, authorIdentity.address); - await setIdentity(authorIdentity); - await requestJudgement(authorIdentity, authorityIdentity.address); - await provideJudgement(authorityIdentity, authorIdentity.address); const { mnemonic: issuerMnemonic, document: issuerDid } = await createDid( authorIdentity