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

Package updates & Network Membership #119

Merged
merged 5 commits into from
Sep 19, 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
25 changes: 8 additions & 17 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ module.exports = {
ecmaVersion: 2018,
sourceType: 'module',
project: './tsconfig.json',
tsconfigRootDir: __dirname,
extraFileExtensions: ['.json'],
},
plugins: [
'@typescript-eslint',
Expand All @@ -37,7 +39,7 @@ module.exports = {
devDependencies: [
'**/*.test.ts',
'**/*.spec.ts',
'**/__integrationtests__/*',
'tests/**/*',
'**/webpack.config.js',
],
},
Expand Down Expand Up @@ -141,7 +143,7 @@ module.exports = {
'jsdoc/check-tag-names': [
'warn',
{
definedTags: ['group', 'packageDocumentation'],
definedTags: ['packageDocumentation'],
},
],
'@typescript-eslint/no-var-requires': 'off',
Expand All @@ -151,31 +153,20 @@ module.exports = {
'no-console': 'off',
},
},
{
files: ['**/__integrationtests__/*.ts'],
rules: {
'import/extensions': 'off',
'jsdoc/require-jsdoc': 'off',
'no-console': 'off',
},
},
{
files: ['**/augment-api/src/interfaces/**/*.ts'],
rules: {
'license-header/header': 'off',
},
},
{
files: ['tests/*'],
files: ['tests/**/*'],
rules: {
'import/extensions': 'off',
'jsdoc/require-jsdoc': 'off',
'no-console': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: ['tests/*', 'tests/bundle.spec.ts'],
},
],
'import/no-extraneous-dependencies': 'off',
},
},
],
Expand Down
4 changes: 3 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
jsonabc.js
jsonabc.d.ts
dist
lib
*.json
!package.json
jest.*
coverage
**/augment-api/src/interfaces/**/*.ts
**/augment-api/src/interfaces/**/*.ts
24 changes: 12 additions & 12 deletions demo/src/demo-vc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,20 @@ async function main() {
Cord.ConfigService.set({ submitTxResolveOn: Cord.Chain.IS_IN_BLOCK })
await Cord.connect(networkAddress)

// Step 1: Setup Authority
// Step 1: Setup Membership
// Setup transaction author account - CORD Account.

console.log(`\n❄️ New Authority`)
console.log(`\n❄️ New Network Member`)
const authorityAuthorIdentity = Crypto.makeKeypairFromUri(
'//Alice',
'sr25519'
)
// Setup author authority account.
// Setup network member account.
const { account: authorIdentity } = await createAccount()
console.log(`🏦 Author (${authorIdentity.type}): ${authorIdentity.address}`)
console.log(`🏦 Member (${authorIdentity.type}): ${authorIdentity.address}`)
await addAuthority(authorityAuthorIdentity, authorIdentity.address)
console.log(`🔏 Author permissions updated`)
await getChainCredits(authorityAuthorIdentity, authorIdentity.address, 5)
console.log(`💸 Author endowed with credits`)
console.log('✅ Authority created!')
console.log(`🔏 Member permissions updated`)
console.log('✅ Network Member added!')

// Step 2: Setup Identities
console.log(`\n❄️ Demo Identities (KeyRing)`)
Expand Down Expand Up @@ -91,23 +89,26 @@ async function main() {
await createDid(authorIdentity)
const delegateOneKeys = generateKeypairs(delegateOneMnemonic)
console.log(
`🏛 Delegate (${delegateOneDid?.assertionMethod![0].type}): ${delegateOneDid.uri
`🏛 Delegate (${delegateOneDid?.assertionMethod![0].type}): ${
delegateOneDid.uri
}`
)
// Create Delegate Two DID
const { mnemonic: delegateTwoMnemonic, document: delegateTwoDid } =
await createDid(authorIdentity)
const delegateTwoKeys = generateKeypairs(delegateTwoMnemonic)
console.log(
`🏛 Delegate (${delegateTwoDid?.assertionMethod![0].type}): ${delegateTwoDid.uri
`🏛 Delegate (${delegateTwoDid?.assertionMethod![0].type}): ${
delegateTwoDid.uri
}`
)
// Create Delegate 3 DID
const { mnemonic: delegate3Mnemonic, document: delegate3Did } =
await createDid(authorIdentity)
const delegate3Keys = generateKeypairs(delegate3Mnemonic)
console.log(
`🏛 Delegate (${delegate3Did?.assertionMethod![0].type}): ${delegate3Did.uri
`🏛 Delegate (${delegate3Did?.assertionMethod![0].type}): ${
delegate3Did.uri
}`
)
console.log('✅ Identities created!')
Expand Down Expand Up @@ -383,7 +384,6 @@ async function main() {
selfSignatureResult1['verified']
)
}

}

main()
Expand Down
34 changes: 18 additions & 16 deletions demo/src/demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,20 @@ async function main() {
Cord.ConfigService.set({ submitTxResolveOn: Cord.Chain.IS_IN_BLOCK })
await Cord.connect(networkAddress)

// Step 1: Setup Authority
// Step 1: Setup Membership
// Setup transaction author account - CORD Account.

console.log(`\n❄️ New Authority`)
console.log(`\n❄️ New Network Member`)
const authorityAuthorIdentity = Crypto.makeKeypairFromUri(
'//Alice',
'sr25519'
)
// Setup author authority account.
// Setup network member account.
const { account: authorIdentity } = await createAccount()
console.log(`🏦 Author (${authorIdentity.type}): ${authorIdentity.address}`)
console.log(`🏦 Member (${authorIdentity.type}): ${authorIdentity.address}`)
await addAuthority(authorityAuthorIdentity, authorIdentity.address)
console.log(`🔏 Author permissions updated`)
await getChainCredits(authorityAuthorIdentity, authorIdentity.address, 5)
console.log(`💸 Author endowed with credits`)
console.log('✅ Authority created!')
console.log(`🔏 Member permissions updated`)
console.log('✅ Network Member added!')

// Step 2: Setup Identities
console.log(`\n❄️ Demo Identities (KeyRing)`)
Expand Down Expand Up @@ -198,18 +196,18 @@ async function main() {

// Step 4: Delegate creates a new Verifiable Document
console.log(`\n❄️ Verifiable Document Creation `)
let callBackFn = async ({ data }) => ({
signature: delegateTwoKeys.authentication.sign(data),
keyType: delegateTwoKeys.authentication.type,
keyUri: `${delegateTwoDid.uri}${delegateTwoDid.authentication[0].id}`,
})

const document = await createDocument(
holderDid.uri,
delegateTwoDid.uri,
schema,
registryDelegate,
registry.identifier,
callBackFn
async ({ data }) => ({
signature: delegateTwoKeys.authentication.sign(data),
keyType: delegateTwoKeys.authentication.type,
keyUri: `${delegateTwoDid.uri}${delegateTwoDid.authentication[0].id}`,
})
)
console.dir(document, {
depth: null,
Expand All @@ -229,7 +227,7 @@ async function main() {
// Step 5: Delegate updates the Verifiable Document
console.log('\n🖍️ Stream update...\n')

let updatedContent: any = {
let updatedContent: Cord.IContent = {
name: 'Adi',
age: 23,
id: '123456789987654321',
Expand All @@ -251,7 +249,11 @@ async function main() {
document,
updatedContent,
schema,
callBackFn,
async ({ data }) => ({
signature: delegateTwoKeys.authentication.sign(data),
keyType: delegateTwoKeys.authentication.type,
keyUri: `${delegateTwoDid.uri}${delegateTwoDid.authentication[0].id}`,
}),
delegateTwoDid.uri,
authorIdentity,
delegateTwoKeys
Expand Down
2 changes: 1 addition & 1 deletion demo/src/utils/createAuthorities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export async function addAuthority(
) {
const api = Cord.ConfigService.get('api')

const callTx = api.tx.extrinsicAuthorship.add([authority])
const callTx = api.tx.networkMembership.nominate(authority, false)

const sudoTx = await api.tx.sudo.sudo(callTx)

Expand Down
6 changes: 4 additions & 2 deletions demo/src/utils/createDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ export async function createDocument(
pin: 54032,
location: {
state: 'karnataka',
}
}
country: 'india',
},
},
},
holder,
issuer
Expand All @@ -40,6 +41,7 @@ export async function createDocument(
authorization,
registry,
signCallback,
options: {},
})
return document
}
2 changes: 1 addition & 1 deletion demo/src/utils/generateDid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export async function createDid(
await Cord.Chain.signAndSubmitTx(didCreationTx, submitterAccount)

const didUri = Cord.Did.getDidUriFromKey(authentication)
const encodedDid = await api.call.did.query(Cord.Did.toChain(didUri))
const encodedDid = await api.call.didApi.query(Cord.Did.toChain(didUri))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Vikastc @ujjwal6792 Please note this change. With the cord.js upgrade, this would be impacting the cord-apis repo.

const { document } = Cord.Did.linkedInfoFromChain(encodedDid)

if (!document) {
Expand Down
2 changes: 1 addition & 1 deletion demo/src/utils/queryDidName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export async function getDidDocFromName(
console.log(`\n❄️ Resolve DID name ${didName} `)

// Query the owner of the provided didName.
const encodedDidNameOwner = await api.call.did.queryByName(didName)
const encodedDidNameOwner = await api.call.didApi.queryByName(didName)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Vikastc @ujjwal6792 same here, impact on cord-apis repo.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok


const {
document: { uri },
Expand Down
21 changes: 13 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,17 @@
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
},
"devDependencies": {
"@babel/preset-env": "^7.20.2",
"@commitlint/cli": "^9.0.1",
"@commitlint/config-conventional": "^9.0.1",
"@playwright/test": "^1.21.1",
"@types/jest": "^27.4.0",
"@types/jest": "^29.5.3",
"@typescript-eslint/eslint-plugin": "^5.7.0",
"@typescript-eslint/parser": "^5.7.0",
"eslint": "^7.32.0",
Expand All @@ -52,16 +60,13 @@
"eslint-plugin-license-header": "^0.2.1",
"eslint-plugin-prettier": "^4.0.0",
"husky": "^7.0.0",
"jest": "^27.4.7",
"jest-docblock": "^27.4.0",
"jest-runner": "^27.4.6",
"jest-runner-groups": "^2.1.0",
"jest": "^29.6.1",
"moment": "^2.29.1",
"prettier": "^2.4.1",
"rimraf": "^3.0.2",
"testcontainers": "^8.6.1",
"ts-jest": "^27.1.2",
"ts-jest-resolver": "^2.0.0",
"testcontainers": "^9.0.0",
"ts-jest": "^29.1.1",
"ts-jest-resolver": "^2.0.1",
"tsx": "^3.4.3",
"typedoc": "^0.23.0",
"typescript": "^4.8.3"
Expand Down
7 changes: 7 additions & 0 deletions packages/augment-api/extraDefs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"types": "../lib/interfaces/extraDefs/index.d.ts",
"//": [
"This is a fallback to support the extraDefs subpath export for module systems that do not support the package.json exports field.",
"Inspired by https://github.com/andrewbranch/example-subpath-exports-ts-compat/blob/1ffe3425b0a7ad8ecdf3c373f76f431ee341366b/examples/node_modules/package-json-redirects/."
]
}
3 changes: 3 additions & 0 deletions packages/augment-api/index.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This package does not contain executable code. Index files are included only to allow api augmentation using `require('@cord.network/augment-api')`.

module.exports = {}
3 changes: 3 additions & 0 deletions packages/augment-api/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This package does not contain executable code. Index files are included only to allow api augmentation using `require('@cord.network/augment-api')`.

exports = {}
2 changes: 1 addition & 1 deletion packages/augment-api/metadata/cord.json

Large diffs are not rendered by default.

40 changes: 21 additions & 19 deletions packages/augment-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,50 @@
"name": "@cord.network/augment-api",
"version": "0.8.0-3",
"description": "",
"main": "./lib/cjs/index.js",
"module": "./lib/esm/index.js",
"types": "./lib/cjs/index.d.ts",
"types": "./lib/index.d.ts",
"type": "module",
"main": "./index.cjs",
"exports": {
".": {
"types": "./lib/cjs/index.d.ts",
"import": "./lib/esm/index.js",
"require": "./lib/cjs/index.js"
"types": "./lib/index.d.ts",
"import": "./index.mjs",
"require": "./index.cjs"
},
"./extraDefs": {
"types": "./lib/interfaces/extraDefs/index.d.ts"
}
},
"files": [
"lib/**/*"
"lib/**/*",
"index.mjs",
"index.cjs",
"extraDefs/*"
],
"scripts": {
"clean": "rimraf ./lib",
"build": "yarn clean && yarn build:ts",
"build:types": "yarn generate:defs && yarn generate:meta && yarn build:fixes",
"build:fixes": "node scripts/fixTypes.mjs",
"build:ts": "yarn build:cjs && yarn build:esm",
"build:cjs": "tsc --declaration -p tsconfig.build.json && echo '{\"type\":\"commonjs\"}' > ./lib/cjs/package.json",
"build:esm": "tsc --declaration -p tsconfig.esm.json && echo '{\"type\":\"module\"}' > ./lib/esm/package.json",
"generate:defs": "ts-node --skip-project ../../node_modules/.bin/polkadot-types-from-defs --package @cord.network/augment-api --input ./src/interfaces --endpoint ./metadata/cord.json",
"generate:meta": "ts-node --skip-project ../../node_modules/.bin/polkadot-types-from-chain --package @cord.network/augment-api --endpoint ./metadata/cord.json --output ./src/interfaces --strict",
"update-metadata": "node ./scripts/fetchMetadata.js -o './metadata/cord.json' -e 'wss://staging.cord.network/'"
"build:ts": "tsc -p tsconfig.build.json",
"generate:defs": "ts-node --esm -P tsconfig.build.json ../../node_modules/.bin/polkadot-types-from-defs --package @cord.network/augment-api --input ./src/interfaces --endpoint ./metadata/cord.json",
"generate:meta": "ts-node --esm -P tsconfig.build.json ../../node_modules/.bin/polkadot-types-from-chain --package @cord.network/augment-api --endpoint ./metadata/cord.json --output ./src/interfaces --strict",
"update-metadata": "node ./scripts/fetchMetadata.cjs -o './metadata/cord.json' -e 'wss://staging.cord.network/'"
},
"repository": "github:dhiway/cord.js",
"engines": {
"node": ">=14.0"
"node": ">=16.0"
},
"author": "Dhiway <[email protected]>",
"license": "Apache-2.0",
"bugs": "https://github.com/dhiway/cord.js/issues",
"homepage": "https://github.com/dhiway/cord.js#readme",
"devDependencies": {
"@polkadot/api": "^9.10.2",
"@polkadot/typegen": "^9.10.2",
"@types/websocket": "^1.0.5",
"@polkadot/api": "^10.4.0",
"@polkadot/typegen": "^10.4.0",
"glob": "^7.1.1",
"rimraf": "^3.0.2",
"ts-node": "^10.9.0",
"ts-node": "^10.4.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: this is lowering the version. All others are about increments.

"typescript": "^4.8.3",
"websocket": "^1.0.34",
"yargs": "^16.2.0"
},
"dependencies": {
Expand Down
Loading
Loading