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

network dispatch key changes #146

Merged
merged 2 commits into from
Dec 1, 2023
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
40 changes: 22 additions & 18 deletions demo/src/func-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ async function main() {
issuerDid.uri,
authorIdentity,
async ({ data }) => ({
signature: issuerKeys.assertionMethod.sign(data),
keyType: issuerKeys.assertionMethod.type,
signature: issuerKeys.authentication.sign(data),
keyType: issuerKeys.authentication.type,
})
)
console.dir(space, {
Expand Down Expand Up @@ -231,17 +231,17 @@ async function main() {
depth: null,
colors: true,
})
const schemaId = await Cord.Schema.dispatchToChain(
const schemaUri = await Cord.Schema.dispatchToChain(
schemaProperties.schema,
issuerDid.uri,
authorIdentity,
space.authorization,
async ({ data }) => ({
signature: issuerKeys.assertionMethod.sign(data),
keyType: issuerKeys.assertionMethod.type,
signature: issuerKeys.authentication.sign(data),
keyType: issuerKeys.authentication.type,
})
)
console.log(`✅ Schema - ${schemaId} - added!`)
console.log(`✅ Schema - ${schemaUri} - added!`)

console.log(`\n❄️ Query From Chain - Schema `)
const schemaFromChain = await Cord.Schema.fetchFromChain(
Expand Down Expand Up @@ -269,7 +269,8 @@ async function main() {
const statementEntry = Cord.Statement.buildFromProperties(
credHash,
space.uri,
issuerDid.uri
issuerDid.uri,
schemaUri
)
console.dir(statementEntry, {
depth: null,
Expand All @@ -282,8 +283,8 @@ async function main() {
authorIdentity,
space.authorization,
async ({ data }) => ({
signature: issuerKeys.assertionMethod.sign(data),
keyType: issuerKeys.assertionMethod.type,
signature: issuerKeys.authentication.sign(data),
keyType: issuerKeys.authentication.type,
})
)

Expand Down Expand Up @@ -314,8 +315,8 @@ async function main() {
authorIdentity,
delegateAuth as Cord.AuthorizationUri,
async ({ data }) => ({
signature: delegateTwoKeys.assertionMethod.sign(data),
keyType: delegateTwoKeys.assertionMethod.type,
signature: delegateTwoKeys.authentication.sign(data),
keyType: delegateTwoKeys.authentication.type,
})
)
console.log(`✅ Statement element registered - ${updatedStatement}`)
Expand All @@ -325,7 +326,8 @@ async function main() {
statementEntry.elementUri,
credHash,
issuerDid.uri,
space.uri
space.uri,
schemaUri
)

if (verificationResult.isValid) {
Expand All @@ -344,10 +346,12 @@ async function main() {

if (anotherVerificationResult.isValid) {
console.log(
`✅ Verification successful! "${updatedStatementEntry.elementUri}" 🎉`
`\n✅ Verification successful! "${updatedStatementEntry.elementUri}" 🎉`
)
} else {
console.log(`🚫 Verification failed! - "${verificationResult.message}" 🚫`)
console.log(
`\n🚫 Verification failed! - "${verificationResult.message}" 🚫`
)
}

console.log(`\n❄️ Revoke Statement - ${updatedStatementEntry.elementUri}`)
Expand All @@ -357,8 +361,8 @@ async function main() {
authorIdentity,
delegateAuth,
async ({ data }) => ({
signature: delegateTwoKeys.assertionMethod.sign(data),
keyType: delegateTwoKeys.assertionMethod.type,
signature: delegateTwoKeys.authentication.sign(data),
keyType: delegateTwoKeys.authentication.type,
})
)
console.log(`✅ Statement revoked!`)
Expand Down Expand Up @@ -388,8 +392,8 @@ async function main() {
authorIdentity,
delegateAuth,
async ({ data }) => ({
signature: delegateTwoKeys.assertionMethod.sign(data),
keyType: delegateTwoKeys.assertionMethod.type,
signature: delegateTwoKeys.authentication.sign(data),
keyType: delegateTwoKeys.authentication.type,
})
)
console.log(`✅ Statement revoked!`)
Expand Down
13 changes: 6 additions & 7 deletions packages/did/src/DidDetails/FullDidDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,21 @@ import {
} from '../Did.chain.js'

const methodMapping: Record<string, VerificationKeyRelationship | undefined> = {
statement: 'assertionMethod',
schema: 'assertionMethod',
statement: 'authentication',
schema: 'authentication',
'chainSpace.addAdminDelegate': 'capabilityDelegation',
'chainSpace.addAuditDelegate': 'capabilityDelegation',
'chainSpace.addDelegate': 'capabilityDelegation',
'chainSpace.removeDelegate': 'capabilityDelegation',
'chainSpace.create': 'assertionMethod',
'chainSpace.archive': 'assertionMethod',
'chainSpace.restore': 'assertionMethod',
unique: 'assertionMethod',
'chainSpace.create': 'authentication',
'chainSpace.archive': 'authentication',
'chainSpace.restore': 'authentication',
did: 'authentication',
'did.create': undefined,
'did.submitDidCall': undefined,
didLookup: 'authentication',
didName: 'authentication',
score: 'assertionMethod',
score: 'authentication',
}

function getKeyRelationshipForMethod(
Expand Down
1 change: 0 additions & 1 deletion packages/statement/src/Statement.chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,6 @@ export async function fetchStatementDetailsfromChain(
)
}

console.log(statementDetails)
const schemaUri =
statementDetails.schemaUri !== undefined
? identifierToUri(statementDetails.schemaUri)
Expand Down
10 changes: 4 additions & 6 deletions packages/statement/src/Statement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import type {
SpaceUri,
DidUri,
StatementUri,
PartialStatementEntry,
} from '@cord.network/types'
import { DataUtils, SDKErrors } from '@cord.network/utils'
import { checkIdentifier, updateStatementUri } from '@cord.network/identifier'
Expand Down Expand Up @@ -178,17 +179,15 @@ export function buildFromUpdateProperties(
stmtUri: StatementUri,
digest: HexString,
spaceUri: SpaceUri,
creatorUri: DidUri,
schemaUri?: SchemaUri
): IStatementEntry {
creatorUri: DidUri
): PartialStatementEntry {
const statementUri = updateStatementUri(stmtUri, digest)

// TODO fetch on-chain data and compare the update inputs
const statement = {
elementUri: statementUri,
digest,
creatorUri,
spaceUri,
schemaUri: schemaUri || undefined,
}
verifyDataStructure(statement)
return statement
Expand Down Expand Up @@ -251,7 +250,6 @@ export async function verifyAgainstProperties(
schemaUri?: SchemaUri
): Promise<{ isValid: boolean; message: string }> {
try {
console.log(stmtUri)
const statementStatus = await fetchStatementDetailsfromChain(stmtUri)

if (!statementStatus) {
Expand Down
2 changes: 2 additions & 0 deletions packages/types/src/Statement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export interface IStatementEntry {
schemaUri?: SchemaUri | undefined
}

export type PartialStatementEntry = Omit<IStatementEntry, 'schemaUri'>

export interface IStatementDetails {
uri: StatementUri
digest: StatementDigest
Expand Down
Loading