Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update demo to use SDK method for creating DID #227

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions demo/src/asset-benchmark.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as Cord from "@cord.network/sdk";
import { addNetworkMember } from "./utils/createAuthorities.js";
import { createAccount } from "./utils/createAccount.js";
import { createDid } from "./utils/generateDid";
import { BN } from '@polkadot/util'
import { uriToIdentifier } from '@cord.network/identifier'

Expand Down Expand Up @@ -49,7 +48,7 @@ async function main() {
await addNetworkMember(networkAuthorityIdentity, issuerIdentity.address);
console.log("✅ Issuer Identity created!");

const { mnemonic: issuerMnemonic, document: issuerDid } = await createDid(
const { mnemonic: issuerMnemonic, document: issuerDid } = await Cord.Did.createDid(
networkAuthorityIdentity
)
const issuerKeys = Cord.Utils.Keys.generateKeypairs(issuerMnemonic, 'sr25519')
Expand Down
7 changes: 3 additions & 4 deletions demo/src/asset-tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {

import { AssetTypeOf, IAssetProperties } from "./utils/asset-types.js";
*/
import { createDid } from "./utils/generateDid";

const { NETWORK_ADDRESS, ANCHOR_URI } = process.env;

Expand All @@ -38,22 +37,22 @@ async function main() {

// const { account: issuerIdentity } = createAccount();
// Create issuer DID
const { mnemonic: issuerMnemonic, document: issuerDid } = await createDid(
const { mnemonic: issuerMnemonic, document: issuerDid } = await Cord.Did.createDid(
networkAuthorityIdentity
)
const issuerKeys = Cord.Utils.Keys.generateKeypairs(issuerMnemonic, 'sr25519')
console.log(
`🏛 Issuer (${issuerDid?.assertionMethod![0].type}): ${issuerDid.uri}`
)

const { mnemonic: holderMnemonic, document: holderDid } = await createDid(
const { mnemonic: holderMnemonic, document: holderDid } = await Cord.Did.createDid(
networkAuthorityIdentity
)
const holderKeys = Cord.Utils.Keys.generateKeypairs(holderMnemonic, 'sr25519')
console.log(
`🏛 Holder (${holderDid?.assertionMethod![0].type}): ${holderDid.uri}`
)
const { mnemonic: holder2Mnemonic, document: holder2Did } = await createDid(
const { mnemonic: holder2Mnemonic, document: holder2Did } = await Cord.Did.createDid(
networkAuthorityIdentity
)
console.log(
Expand Down
3 changes: 1 addition & 2 deletions demo/src/asset-vc-benchmark.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as Cord from "@cord.network/sdk";
import { addNetworkMember } from "./utils/createAuthorities.js";
import { createAccount } from "./utils/createAccount.js";
import { createDid } from "./utils/generateDid";
import { BN } from '@polkadot/util'
import { uriToIdentifier } from '@cord.network/identifier'

Expand Down Expand Up @@ -49,7 +48,7 @@ async function main() {
await addNetworkMember(networkAuthorityIdentity, issuerIdentity.address);
console.log("✅ Issuer Identity created!");

const { mnemonic: issuerMnemonic, document: issuerDid } = await createDid(
const { mnemonic: issuerMnemonic, document: issuerDid } = await Cord.Did.createDid(
networkAuthorityIdentity
)
const issuerKeys = Cord.Utils.Keys.generateKeypairs(issuerMnemonic, 'sr25519')
Expand Down
7 changes: 3 additions & 4 deletions demo/src/asset-vc-tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { addNetworkMember } from "./utils/createAuthorities.js";
import { createAccount } from "./utils/createAccount.js";

import * as vcExport from "@cord.network/vc-export";
import { createDid } from "./utils/generateDid";
import PalletAssetVcAssetEntry from '@polkadot/types/lookup';

const { NETWORK_ADDRESS, ANCHOR_URI } = process.env;
Expand Down Expand Up @@ -81,22 +80,22 @@ async function main() {

// const { account: issuerIdentity } = createAccount();
// Create issuer DID
const { mnemonic: issuerMnemonic, document: issuerDid } = await createDid(
const { mnemonic: issuerMnemonic, document: issuerDid } = await Cord.Did.createDid(
networkAuthorityIdentity
)
const issuerKeys = Cord.Utils.Keys.generateKeypairs(issuerMnemonic, 'sr25519')
console.log(
`🏛 Issuer (${issuerDid?.assertionMethod![0].type}): ${issuerDid.uri}`
)

const { mnemonic: holderMnemonic, document: holderDid } = await createDid(
const { mnemonic: holderMnemonic, document: holderDid } = await Cord.Did.createDid(
networkAuthorityIdentity
)
const holderKeys = Cord.Utils.Keys.generateKeypairs(holderMnemonic, 'sr25519')
console.log(
`🏛 Holder (${holderDid?.assertionMethod![0].type}): ${holderDid.uri}`
)
const { mnemonic: holder2Mnemonic, document: holder2Did } = await createDid(
const { mnemonic: holder2Mnemonic, document: holder2Did } = await Cord.Did.createDid(
networkAuthorityIdentity
)
console.log(
Expand Down
13 changes: 6 additions & 7 deletions demo/src/comp.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as Cord from '@cord.network/sdk'
import { UUID, Crypto } from '@cord.network/utils'
import { createDid } from './utils/generateDid'
import { createDidName } from './utils/generateDidName'
import { getDidDocFromName } from './utils/queryDidName'
// import { ensureStoredSchema } from './utils/generateSchema'
Expand Down Expand Up @@ -76,23 +75,23 @@ async function main() {

/* Creating the DIDs for the different parties involved in the demo. */
// Create Verifier DID
const { mnemonic: verifierMnemonic, document: verifierDid } = await createDid(
const { mnemonic: verifierMnemonic, document: verifierDid } = await Cord.Did.createDid(
authorIdentity
)
const verifierKeys = Cord.Utils.Keys.generateKeypairs(verifierMnemonic)
console.log(
`🏢 Verifier (${verifierDid.assertionMethod![0].type}): ${verifierDid.uri}`
)
// Create Holder DID
const { mnemonic: holderMnemonic, document: holderDid } = await createDid(
const { mnemonic: holderMnemonic, document: holderDid } = await Cord.Did.createDid(
authorIdentity
)
const holderKeys = Cord.Utils.Keys.generateKeypairs(holderMnemonic)
console.log(
`👩‍⚕️ Holder (${holderDid.assertionMethod![0].type}): ${holderDid.uri}`
)
// Create issuer DID
const { mnemonic: issuerMnemonic, document: issuerDid } = await createDid(
const { mnemonic: issuerMnemonic, document: issuerDid } = await Cord.Did.createDid(
authorIdentity
)
const issuerKeys = Cord.Utils.Keys.generateKeypairs(issuerMnemonic)
Expand All @@ -109,7 +108,7 @@ async function main() {
// })
// Create Delegate One DID
const { mnemonic: delegateOneMnemonic, document: delegateOneDid } =
await createDid(authorIdentity)
await Cord.Did.createDid(authorIdentity)
const delegateOneKeys = Cord.Utils.Keys.generateKeypairs(delegateOneMnemonic)
console.log(
`🏛 Delegate (${delegateOneDid?.assertionMethod![0].type}): ${
Expand All @@ -118,7 +117,7 @@ async function main() {
)
// Create Delegate Two DID
const { mnemonic: delegateTwoMnemonic, document: delegateTwoDid } =
await createDid(authorIdentity)
await Cord.Did.createDid(authorIdentity)
const delegateTwoKeys = Cord.Utils.Keys.generateKeypairs(delegateTwoMnemonic)
console.log(
`🏛 Delegate (${delegateTwoDid?.assertionMethod![0].type}): ${
Expand All @@ -127,7 +126,7 @@ async function main() {
)
// Create Delegate 3 DID
const { mnemonic: delegate3Mnemonic, document: delegate3Did } =
await createDid(authorIdentity)
await Cord.Did.createDid(authorIdentity)
const delegate3Keys = Cord.Utils.Keys.generateKeypairs(delegate3Mnemonic)
console.log(
`🏛 Delegate (${delegate3Did?.assertionMethod![0].type}): ${
Expand Down
13 changes: 6 additions & 7 deletions demo/src/func-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as Cord from '@cord.network/sdk'
// import { UUID, Crypto } from '@cord.network/utils'
import { createDid } from './utils/generateDid'
import { createDidName } from './utils/generateDidName'
import { getDidDocFromName } from './utils/queryDidName'
import { randomUUID } from 'crypto'
Expand Down Expand Up @@ -62,7 +61,7 @@ async function main() {
/* Creating the DIDs for the different parties involved in the demo. */
// Create Verifier DID
const { mnemonic: verifierMnemonic, document: verifierDid } =
await createDid(authorIdentity)
await Cord.Did.createDid(authorIdentity)
const verifierKeys = Cord.Utils.Keys.generateKeypairs(
verifierMnemonic,
'sr25519'
Expand All @@ -72,14 +71,14 @@ async function main() {
)
// Create Holder DID
const { mnemonic: holderMnemonic, document: holderDid } =
await createDid(authorIdentity)
await Cord.Did.createDid(authorIdentity)
const holderKeys = Cord.Utils.Keys.generateKeypairs(holderMnemonic, 'sr25519')
console.log(
`👩‍⚕️ Holder (${holderDid.assertionMethod![0].type}): ${holderDid.uri}`
)
// Create issuer DID
const { mnemonic: issuerMnemonic, document: issuerDid } =
await createDid(authorIdentity)
await Cord.Did.createDid(authorIdentity)
const issuerKeys = Cord.Utils.Keys.generateKeypairs(issuerMnemonic, 'sr25519')
console.log(
`🏛 Issuer (${issuerDid?.assertionMethod![0].type}): ${issuerDid.uri}`
Expand All @@ -94,7 +93,7 @@ async function main() {
})
// Create Delegate One DID
const { mnemonic: delegateOneMnemonic, document: delegateOneDid } =
await createDid(authorIdentity)
await Cord.Did.createDid(authorIdentity)
const delegateOneKeys = Cord.Utils.Keys.generateKeypairs(
delegateOneMnemonic,
'sr25519'
Expand All @@ -106,7 +105,7 @@ async function main() {
)
// Create Delegate Two DID
const { mnemonic: delegateTwoMnemonic, document: delegateTwoDid } =
await createDid(authorIdentity)
await Cord.Did.createDid(authorIdentity)
const delegateTwoKeys = Cord.Utils.Keys.generateKeypairs(
delegateTwoMnemonic,
'sr25519'
Expand All @@ -118,7 +117,7 @@ async function main() {
)
// Create Delegate 3 DID
const { mnemonic: delegate3Mnemonic, document: delegate3Did } =
await createDid(authorIdentity)
await Cord.Did.createDid(authorIdentity)
const delegate3Keys = Cord.Utils.Keys.generateKeypairs(
delegate3Mnemonic,
'sr25519'
Expand Down
7 changes: 3 additions & 4 deletions demo/src/network-score-test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as Cord from '@cord.network/sdk'
import { createDid } from './utils/generateDid'
import { createDidName } from './utils/generateDidName'
import { getDidDocFromName } from './utils/queryDidName'
import { addNetworkMember } from './utils/createAuthorities'
Expand All @@ -26,20 +25,20 @@ async function main() {
console.log('✅ Network Membership Approved! 🎉\n')

const { mnemonic: chainSpaceAdminMnemonic, document: chainSpaceAdminDid } =
await createDid(networkAuthorIdentity)
await Cord.Did.createDid(networkAuthorIdentity)
const chainSpaceAdminKeys = Cord.Utils.Keys.generateKeypairs(chainSpaceAdminMnemonic, 'sr25519')
console.log(
`🔐 Network Score Admin (${chainSpaceAdminDid.authentication[0].type}): ${chainSpaceAdminDid.uri}`
)
const { mnemonic: networkProviderMnemonic, document: networkProviderDid } =
await createDid(networkAuthorIdentity)
await Cord.Did.createDid(networkAuthorIdentity)
const networkProviderKeys = Cord.Utils.Keys.generateKeypairs(networkProviderMnemonic, 'sr25519')
console.log(
`🔐 Network Participant (Provider) (${networkProviderDid.authentication[0].type}): ${networkProviderDid.uri}`
)

const { mnemonic: networkAuthorMnemonic, document: networkAuthorDid } =
await createDid(networkAuthorIdentity)
await Cord.Did.createDid(networkAuthorIdentity)
const networkAuthorKeys = Cord.Utils.Keys.generateKeypairs(networkAuthorMnemonic, 'sr25519')
console.log(
`🔐 Network Author (API -> Node) (${networkAuthorDid.authentication[0].type}): ${networkAuthorDid.uri}`
Expand Down
58 changes: 0 additions & 58 deletions demo/src/utils/generateDid.ts

This file was deleted.

11 changes: 2 additions & 9 deletions demo/src/welcome-developer.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
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 and Creating a Chainspace.
Expand Down Expand Up @@ -51,7 +44,7 @@ async function main() {

await addNetworkMember(authorityAuthorIdentity, authorIdentity.address);

const { mnemonic: issuerMnemonic, document: issuerDid } = await createDid(
const { mnemonic: issuerMnemonic, document: issuerDid } = await Cord.Did.createDid(
authorIdentity
);
const issuerKeys = Cord.Utils.Keys.generateKeypairs(
Expand All @@ -60,7 +53,7 @@ async function main() {
);

const { mnemonic: delegateTwoMnemonic, document: delegateTwoDid } =
await createDid(authorIdentity);
await Cord.Did.createDid(authorIdentity);

const spaceProperties = await Cord.ChainSpace.buildFromProperties(
issuerDid.uri
Expand Down