Skip to content

Commit

Permalink
Stream -> Statement: rename the feature (#134)
Browse files Browse the repository at this point in the history
* Stream -> Statement: rename the feature

Signed-off-by: Amar Tumballi <[email protected]>

* allow multiple digests packed in one create call

Signed-off-by: Amar Tumballi <[email protected]>

* update digest-mapping as double map

Signed-off-by: Amar Tumballi <[email protected]>

---------

Signed-off-by: Amar Tumballi <[email protected]>
  • Loading branch information
amarts authored Oct 11, 2023
1 parent 2153124 commit c63dc4c
Show file tree
Hide file tree
Showing 48 changed files with 587 additions and 576 deletions.
4 changes: 2 additions & 2 deletions demo/src/demo-messaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from './utils/generateRegistry'
import { createDocument } from './utils/createDocument'
import { createPresentation } from './utils/createPresentation'
import { createStream } from './utils/createStream'
import { createStatement } from './utils/createStatement'
import { randomUUID } from 'crypto'
import { getChainCredits, addAuthority } from './utils/createAuthorities'
import { createAccount } from './utils/createAccount'
Expand Down Expand Up @@ -207,7 +207,7 @@ async function main() {
depth: null,
colors: true,
})
await createStream(
await createStatement(
delegateTwoDid.uri,
authorIdentity,
async ({ data }) => ({
Expand Down
54 changes: 27 additions & 27 deletions demo/src/demo-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ async function main() {
console.log(e.errorCode, '-', e.message)
}

// Step 6: Create a new Stream
console.log(`\n❄️ Stream Creation `)
// Step 6: Create a new Statement
console.log(`\n❄️ Statement Creation `)
console.log(`🔗 ${newSpace.identifier} `)
console.log(`🔗 ${newSchema.identifier} `)

Expand All @@ -155,61 +155,61 @@ async function main() {
country: 'India',
credit: 1000,
}
let schemaStream = Cord.Content.fromSchemaAndContent(
let schemaStatement = Cord.Content.fromSchemaAndContent(
newSchema,
content,
employeeIdentity.address,
holderIdentity.address
)
console.dir(schemaStream, { depth: null, colors: true })
console.dir(schemaStatement, { depth: null, colors: true })

let newStreamContent = Cord.ContentStream.fromContent(
schemaStream,
let newStatementContent = Cord.ContentStatement.fromContent(
schemaStatement,
employeeIdentity,
{ space: newSpace.identifier }
)
console.dir(newStreamContent, { depth: null, colors: true })
console.dir(newStatementContent, { depth: null, colors: true })

let newStream = Cord.Stream.fromContentStream(newStreamContent)
let newStatement = Cord.Statement.fromContentStatement(newStatementContent)

let streamCreationExtrinsic = await Cord.Stream.create(newStream)
console.dir(newStream, { depth: null, colors: true })
let statementCreationExtrinsic = await Cord.Statement.create(newStatement)
console.dir(newStatement, { depth: null, colors: true })

try {
await Cord.Chain.signAndSubmitTx(streamCreationExtrinsic, entityIdentity, {
await Cord.Chain.signAndSubmitTx(statementCreationExtrinsic, entityIdentity, {
resolveOn: Cord.Chain.IS_IN_BLOCK,
rejectOn: Cord.Chain.IS_ERROR,
})
console.log('✅ Stream created!')
console.log('✅ Statement created!')
} catch (e: any) {
console.log(e.errorCode, '-', e.message)
}

// Step 7: Add Stream Metadata
console.log(`\n❄️ Stream Metadata addition `)
console.log(`🔗 ${newStreamContent.identifier}`)
// Step 7: Add Statement Metadata
console.log(`\n❄️ Statement Metadata addition `)
console.log(`🔗 ${newStatementContent.identifier}`)

let streamMeta = Cord.Meta.fromMetaProperties(
newStreamContent.identifier,
JSON.stringify(newStreamContent),
let statementMeta = Cord.Meta.fromMetaProperties(
newStatementContent.identifier,
JSON.stringify(newStatementContent),
employeeIdentity
)
let streamMetaCreationExtrinsic = await Cord.Meta.setMetadata(streamMeta)
console.dir(streamMeta, {
let statementMetaCreationExtrinsic = await Cord.Meta.setMetadata(statementMeta)
console.dir(statementMeta, {
depth: null,
colors: true,
})

try {
await Cord.Chain.signAndSubmitTx(
streamMetaCreationExtrinsic,
statementMetaCreationExtrinsic,
entityIdentity,
{
resolveOn: Cord.Chain.IS_IN_BLOCK,
rejectOn: Cord.Chain.IS_ERROR,
}
)
console.log('✅ Stream metadata added!')
console.log('✅ Statement metadata added!')
} catch (e: any) {
console.log(e.errorCode, '-', e.message)
}
Expand All @@ -233,13 +233,13 @@ async function main() {
console.dir(spaceMetaData, { depth: null, colors: true })
}

console.log(`\n❄️ Stream Metadata `)
console.log(`🔗 ${newStreamContent.identifier}`)
const streamMetaData = await Cord.Meta.query(newStreamContent.identifier)
if (!streamMetaData) {
console.log(`\n❄️ Statement Metadata `)
console.log(`🔗 ${newStatementContent.identifier}`)
const statementMetaData = await Cord.Meta.query(newStatementContent.identifier)
if (!statementMetaData) {
console.log(`Space metadata not anchored on CORD`)
} else {
console.dir(streamMetaData, { depth: null, colors: true })
console.dir(statementMetaData, { depth: null, colors: true })
}

// Step 9: Clear Space metadata
Expand Down
4 changes: 2 additions & 2 deletions demo/src/demo-sparknet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from './utils/generateRegistry'
import { createDocument } from './utils/createDocument'
import { createPresentation } from './utils/createPresentation'
import { createStream } from './utils/createStream'
import { createStatement } from './utils/createStatement'
import { verifyPresentation } from './utils/verifyPresentation'
import { revokeCredential } from './utils/revokeCredential'
import { randomUUID } from 'crypto'
Expand Down Expand Up @@ -202,7 +202,7 @@ async function main() {
depth: null,
colors: true,
})
await createStream(
await createStatement(
delegateTwoDid.uri,
authorityAuthorIdentity,
async ({ data }) => ({
Expand Down
4 changes: 2 additions & 2 deletions demo/src/demo-staging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from './utils/generateRegistry'
import { createDocument } from './utils/createDocument'
import { createPresentation } from './utils/createPresentation'
import { createStream } from './utils/createStream'
import { createStatement } from './utils/createStatement'
import { verifyPresentation } from './utils/verifyPresentation'
import { revokeCredential } from './utils/revokeCredential'
import { randomUUID } from 'crypto'
Expand Down Expand Up @@ -202,7 +202,7 @@ async function main() {
depth: null,
colors: true,
})
await createStream(
await createStatement(
delegateTwoDid.uri,
authorityAuthorIdentity,
async ({ data }) => ({
Expand Down
72 changes: 36 additions & 36 deletions demo/src/demo-vc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from './utils/generateRegistry'
import { createDocument } from './utils/createDocument'
import { createPresentation } from './utils/createPresentation'
import { createStream } from './utils/createStream'
import { createStatement } from './utils/createStatement'
import { verifyPresentation } from './utils/verifyPresentation'
import { revokeCredential } from './utils/revokeCredential'
import { randomUUID } from 'crypto'
Expand Down Expand Up @@ -208,7 +208,7 @@ async function main() {
depth: null,
colors: true,
})
await createStream(
await createStatement(
delegateTwoDid.uri,
authorIdentity,
async ({ data }) => ({
Expand Down Expand Up @@ -245,11 +245,11 @@ async function main() {
const VCfromPresentation =
vcPresentation.verifiableCredential as VerifiableCredential

const streamResult = await VCUtils.verification.verifyStreamProof(
const statementResult = await VCUtils.verification.verifyStatementProof(
VCfromPresentation,
VCfromPresentation.proof[1]
)
//console.log("\n: VC Proof(1): ", VCfromPresentation.proof[1], streamResult)
//console.log("\n: VC Proof(1): ", VCfromPresentation.proof[1], statementResult)

const selfSignatureResult =
await VCUtils.verification.verifySelfSignatureProof(
Expand All @@ -265,30 +265,30 @@ async function main() {
)
//console.log("\n: VC Proof(2): ", VCfromPresentation.proof[2], digestResult)

const streamSignatureResult =
await VCUtils.verification.verifyStreamSignatureProof(
const statementSignatureResult =
await VCUtils.verification.verifyStatementSignatureProof(
VCfromPresentation,
VCfromPresentation.proof[0]
)

//console.log("\n: VC Proof(0): ", VCfromPresentation.proof[0], streamSignatureResult)
//console.log("\n: VC Proof(0): ", VCfromPresentation.proof[0], statementSignatureResult)

if (
streamResult &&
streamResult['verified'] &&
statementResult &&
statementResult['verified'] &&
digestResult &&
digestResult['verified'] &&
streamSignatureResult &&
streamSignatureResult['verified'] &&
statementSignatureResult &&
statementSignatureResult['verified'] &&
selfSignatureResult &&
selfSignatureResult['verified']
) {
console.log(
'✅',
'Stream-Signature-Proof',
streamSignatureResult['verified'],
'✧ Stream-Proof',
streamResult['verified'],
'Statement-Signature-Proof',
statementSignatureResult['verified'],
'✧ Statement-Proof',
statementResult['verified'],
'✧ Digest-Proof',
digestResult['verified'],
'✧ Self-Signature-Proof',
Expand All @@ -297,10 +297,10 @@ async function main() {
} else {
console.log(
`❌`,
'Stream-Signature-Proof',
streamSignatureResult['verified'],
'✧ Stream-Proof',
streamResult['verified'],
'Statement-Signature-Proof',
statementSignatureResult['verified'],
'✧ Statement-Proof',
statementResult['verified'],
'✧ Digest-Proof',
digestResult['verified'],
'✧ Self-Signature-Proof',
Expand All @@ -322,11 +322,11 @@ async function main() {
console.log(`✅ Credential revoked!`)

/* Test VC & VP after revoke */
const streamResult1 = await VCUtils.verification.verifyStreamProof(
const statementResult1 = await VCUtils.verification.verifyStatementProof(
VCfromPresentation,
VCfromPresentation.proof[1]
)
//console.log("\n: VC Proof(1): ", VCfromPresentation.proof[1], streamResult)
//console.log("\n: VC Proof(1): ", VCfromPresentation.proof[1], statementResult)

const selfSignatureResult1 =
await VCUtils.verification.verifySelfSignatureProof(
Expand All @@ -342,30 +342,30 @@ async function main() {
)
//console.log("\n: VC Proof(2): ", VCfromPresentation.proof[2], digestResult)

const streamSignatureResult1 =
await VCUtils.verification.verifyStreamSignatureProof(
const statementSignatureResult1 =
await VCUtils.verification.verifyStatementSignatureProof(
VCfromPresentation,
VCfromPresentation.proof[0]
)

//console.log("\n: VC Proof(0): ", VCfromPresentation.proof[0], streamSignatureResult)
//console.log("\n: VC Proof(0): ", VCfromPresentation.proof[0], statementSignatureResult)

if (
streamResult1 &&
streamResult1['verified'] &&
statementResult1 &&
statementResult1['verified'] &&
digestResult1 &&
digestResult1['verified'] &&
streamSignatureResult1 &&
streamSignatureResult1['verified'] &&
statementSignatureResult1 &&
statementSignatureResult1['verified'] &&
selfSignatureResult1 &&
selfSignatureResult1['verified']
) {
console.log(
'✅',
'Stream-Signature-Proof',
streamSignatureResult1['verified'],
'✧ Stream-Proof',
streamResult1['verified'],
'Statement-Signature-Proof',
statementSignatureResult1['verified'],
'✧ Statement-Proof',
statementResult1['verified'],
'✧ Digest-Proof',
digestResult1['verified'],
'✧ Self-Signature-Proof',
Expand All @@ -374,10 +374,10 @@ async function main() {
} else {
console.log(
`🚫`,
'Stream-Signature-Proof',
streamSignatureResult1['verified'],
'✧ Stream-Proof',
streamResult1['verified'],
'Statement-Signature-Proof',
statementSignatureResult1['verified'],
'✧ Statement-Proof',
statementResult1['verified'],
'✧ Digest-Proof',
digestResult1['verified'],
'✧ Self-Signature-Proof',
Expand Down
10 changes: 5 additions & 5 deletions demo/src/demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from './utils/generateRegistry'
import { createDocument } from './utils/createDocument'
import { createPresentation } from './utils/createPresentation'
import { createStream } from './utils/createStream'
import { createStatement } from './utils/createStatement'
import { verifyPresentation } from './utils/verifyPresentation'
import { revokeCredential } from './utils/revokeCredential'
import { randomUUID } from 'crypto'
Expand All @@ -21,7 +21,7 @@ import { encryptMessage } from './utils/encrypt_message'
import { generateRequestCredentialMessage } from './utils/request_credential_message'
import { getChainCredits, addAuthority } from './utils/createAuthorities'
import { createAccount } from './utils/createAccount'
import { updateStream } from './utils/updateDocument'
import { updateStatement } from './utils/updateDocument'
import { requestJudgement, setIdentity, setRegistrar, provideJudgement } from './utils/createRegistrar'

// import type {
Expand Down Expand Up @@ -228,7 +228,7 @@ async function main() {
depth: null,
colors: true,
})
await createStream(
await createStatement(
delegateTwoDid.uri,
authorIdentity,
async ({ data }) => ({
Expand All @@ -240,7 +240,7 @@ async function main() {
console.log('✅ Credential created!')

// Step 5: Delegate updates the Verifiable Document
console.log('\n🖍️ Stream update...\n')
console.log('\n🖍️ Statement update...\n')

let updatedContent: Cord.IContent = {
name: 'Adi',
Expand All @@ -260,7 +260,7 @@ async function main() {

console.log('𝌞 Updated content\n', updatedContent)

const updatedDocument = await updateStream(
const updatedDocument = await updateStatement(
document,
updatedContent,
schema,
Expand Down
2 changes: 1 addition & 1 deletion demo/src/identifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ async function main() {
// console.log('base58:', schemaEncodedHash)
// console.log(
// 'base58 Decode:',
// Cord.StreamUtils.hexToString(schemaEncodedHash),
// Cord.StatementUtils.hexToString(schemaEncodedHash),
// schemaEncodedHash
// )
// // console.log(encodeDerivedAddress(newSchema.hash, 1031))
Expand Down
Loading

0 comments on commit c63dc4c

Please sign in to comment.