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

chore: update polkadot dependencies #426

Merged
merged 9 commits into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from 7 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
8 changes: 4 additions & 4 deletions packages/chain-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
"@kiltprotocol/type-definitions": "0.1.23",
"@kiltprotocol/types": "workspace:*",
"@kiltprotocol/utils": "workspace:*",
"@polkadot/api": "^5.4.1",
"@polkadot/keyring": "^7.1.2",
"@polkadot/types": "^5.4.1",
"@polkadot/util": "^7.1.2",
"@polkadot/api": "6.4.2",
"@polkadot/keyring": "7.5.1",
"@polkadot/types": "6.4.2",
"@polkadot/util": "7.5.1",
"typescript-logging": "^0.6.4"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,6 @@ function __makeSubmittableResult(
const eventData = new GenericEventData(
TYPE_REGISTRY,
new Uint8Array([0]),
undefined,
undefined,
{} as any,
'system',
'ExtrinsicSuccess'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ const chainProperties = TYPE_REGISTRY.createType('ChainProperties', {
ss58Format: 38,
})
TYPE_REGISTRY.setChainProperties(chainProperties)
TYPE_REGISTRY.register({
Copy link
Member

@ntn-x2 ntn-x2 Oct 27, 2021

Choose a reason for hiding this comment

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

Q: Do we still need this? I don't see it changed for delegations or DIDs as well.

EDIT: I tried removing it and it did not break the integration tests.

EDIT 2: Nevermind, it broke the unit tests 😂

AttestationAttestationsAttestationDetails: 'AttestationDetails',
})

const AccountId = TYPE_REGISTRY.getOrThrow('AccountId')

Expand Down Expand Up @@ -41,7 +44,9 @@ const chainQueryReturnTuples: {
},
attestation: {
// Attestations: claim-hash -> (ctype-hash, attester-account, delegation-id?, revoked, deposit)?
attestations: TYPE_REGISTRY.getOrUnknown('AttestationDetails'),
attestations: TYPE_REGISTRY.getOrUnknown(
'AttestationAttestationsAttestationDetails'
),
// DelegatedAttestations: delegation-id -> [claim-hash]
delegatedAttestations: TYPE_REGISTRY.getOrUnknown('Hash'),
},
Expand Down
12 changes: 6 additions & 6 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
"@kiltprotocol/did": "workspace:*",
"@kiltprotocol/types": "workspace:*",
"@kiltprotocol/utils": "workspace:*",
"@polkadot/api": "^5.4.1",
"@polkadot/keyring": "^7.1.2",
"@polkadot/types": "^5.4.1",
"@polkadot/types-known": "^5.4.1",
"@polkadot/util": "^7.1.2",
"@polkadot/util-crypto": "^7.1.2",
"@polkadot/api": "6.4.2",
"@polkadot/keyring": "7.5.1",
"@polkadot/types": "6.4.2",
"@polkadot/types-known": "6.4.2",
"@polkadot/util": "7.5.1",
"@polkadot/util-crypto": "7.5.1",
"ajv": "^6.12.5",
"tweetnacl": "^1.0.3",
"typescript-logging": "^0.6.4"
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/__integrationtests__/Attestation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe('When there is an attester, claimer and ctype drivers license', () => {
beforeAll(async () => {
const ctypeExists = await CtypeOnChain(DriversLicense)
if (!ctypeExists) {
attester
await attester
.authorizeExtrinsic(
await DriversLicense.store(),
signer,
Expand Down
17 changes: 17 additions & 0 deletions packages/core/src/__integrationtests__/Delegation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,23 @@ describe('handling queries to data not on chain', () => {
})
})

describe.only('hierarchyDetails', () => {
Copy link
Member

Choose a reason for hiding this comment

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

describe('hierarchyDetails', () => {

EDIT: I also tried removing .only and of course all the rest of the delegation integration tests were also passing, so this can be removed safely.

it('can fetch hierarchyDetails', async () => {
const rootNode = await writeHierarchy(root, DriversLicense.hash)
const delegatedNode = await addDelegation(
rootNode.id,
rootNode.id,
root,
attester
)

const details = await delegatedNode.getHierarchyDetails()

expect(details.cTypeHash).toBe(DriversLicense.hash)
expect(details.id).toBe(rootNode.id)
}, 60_000)
})

afterAll(() => {
disconnect()
})
14 changes: 14 additions & 0 deletions packages/core/src/__integrationtests__/Did.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ describe('write and didDeleteTx', () => {
await expect(
BlockchainUtils.signAndSubmitTx(tx, paymentAccount, {
resolveOn: BlockchainUtils.IS_IN_BLOCK,
reSign: true,
})
).rejects.toThrow()
}, 30_000)
Expand All @@ -82,6 +83,7 @@ describe('write and didDeleteTx', () => {
await expect(
BlockchainUtils.signAndSubmitTx(tx, paymentAccount, {
resolveOn: BlockchainUtils.IS_IN_BLOCK,
reSign: true,
})
).resolves.not.toThrow()

Expand Down Expand Up @@ -111,6 +113,7 @@ describe('write and didDeleteTx', () => {
await expect(
BlockchainUtils.signAndSubmitTx(submittable, paymentAccount, {
resolveOn: BlockchainUtils.IS_IN_BLOCK,
reSign: true,
})
).rejects.toThrow()
})
Expand All @@ -137,6 +140,7 @@ describe('write and didDeleteTx', () => {
await expect(
BlockchainUtils.signAndSubmitTx(submittable, paymentAccount, {
resolveOn: BlockchainUtils.IS_IN_BLOCK,
reSign: true,
})
).resolves.not.toThrow()

Expand All @@ -162,6 +166,7 @@ it('creates and updates DID, and then reclaims the deposit back', async () => {
await expect(
BlockchainUtils.signAndSubmitTx(tx, paymentAccount, {
resolveOn: BlockchainUtils.IS_IN_BLOCK,
reSign: true,
})
).resolves.not.toThrow()

Expand Down Expand Up @@ -197,6 +202,7 @@ it('creates and updates DID, and then reclaims the deposit back', async () => {
await expect(
BlockchainUtils.signAndSubmitTx(tx2, paymentAccount, {
resolveOn: BlockchainUtils.IS_IN_BLOCK,
reSign: true,
})
).resolves.not.toThrow()

Expand All @@ -213,6 +219,7 @@ it('creates and updates DID, and then reclaims the deposit back', async () => {
await expect(
BlockchainUtils.signAndSubmitTx(reclaimDepositTx, paymentAccount, {
resolveOn: BlockchainUtils.IS_IN_BLOCK,
reSign: true,
})
).resolves.not.toThrow()
// Verify that the DID has been deleted
Expand Down Expand Up @@ -250,6 +257,7 @@ describe('DID migration', () => {
await expect(
BlockchainUtils.signAndSubmitTx(extrinsic, paymentAccount, {
resolveOn: BlockchainUtils.IS_IN_BLOCK,
reSign: true,
})
).resolves.not.toThrow()

Expand Down Expand Up @@ -288,6 +296,7 @@ describe('DID migration', () => {
await expect(
BlockchainUtils.signAndSubmitTx(extrinsic, paymentAccount, {
resolveOn: BlockchainUtils.IS_IN_BLOCK,
reSign: true,
})
).resolves.not.toThrow()

Expand Down Expand Up @@ -330,6 +339,7 @@ describe('DID authorization', () => {
await expect(
BlockchainUtils.signAndSubmitTx(tx, paymentAccount, {
resolveOn: BlockchainUtils.IS_IN_BLOCK,
reSign: true,
})
).resolves.not.toThrow()

Expand Down Expand Up @@ -366,6 +376,7 @@ describe('DID authorization', () => {
await expect(
BlockchainUtils.signAndSubmitTx(tx, paymentAccount, {
resolveOn: BlockchainUtils.IS_IN_BLOCK,
reSign: true,
})
).resolves.not.toThrow()

Expand Down Expand Up @@ -401,6 +412,7 @@ describe('DID authorization', () => {
await expect(
BlockchainUtils.signAndSubmitTx(tx, paymentAccount, {
resolveOn: BlockchainUtils.IS_IN_BLOCK,
reSign: true,
})
).resolves.not.toThrow()

Expand All @@ -423,6 +435,7 @@ describe('DID authorization', () => {
await expect(
BlockchainUtils.signAndSubmitTx(tx, paymentAccount, {
resolveOn: BlockchainUtils.IS_IN_BLOCK,
reSign: true,
})
).resolves.not.toThrow()

Expand All @@ -445,6 +458,7 @@ describe('DID authorization', () => {
await expect(
BlockchainUtils.signAndSubmitTx(tx2, paymentAccount, {
resolveOn: BlockchainUtils.IS_IN_BLOCK,
reSign: true,
})
).rejects.toThrow()

Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/attestation/Attestation.chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ function decode(
encoded: Option<AttestationDetails>,
claimHash: string // all the other decoders do not use extra data; they just return partial types
): Attestation | null {
DecoderUtils.assertCodecIsType(encoded, ['Option<AttestationDetails>'])
DecoderUtils.assertCodecIsType(encoded, [
'Option<AttestationAttestationsAttestationDetails>',
])
if (encoded.isSome) {
const chainAttestation = encoded.unwrap()
const attestation: IAttestation = {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/ctype/CType.chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export async function store(ctype: ICType): Promise<SubmittableExtrinsic> {
* @internal
*/
export function decode(encoded: Option<AccountId>): IDidDetails['did'] | null {
DecoderUtils.assertCodecIsType(encoded, ['Option<CtypeCreatorOf>'])
DecoderUtils.assertCodecIsType(encoded, ['Option<AccountId32>'])
return encoded.isSome
? DidUtils.getKiltDidFromIdentifier(encoded.unwrap().toString(), 'full')
: null
Expand Down
20 changes: 13 additions & 7 deletions packages/core/src/delegation/DelegationDecoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import type {
} from '@kiltprotocol/types'
import { Permission } from '@kiltprotocol/types'
import type { Option } from '@polkadot/types'
import type { BTreeSet, Struct } from '@polkadot/types/codec'
import type { Struct, Vec } from '@polkadot/types/codec'
import type { AccountId, Hash } from '@polkadot/types/interfaces/runtime'
import type { Bool, u32 } from '@polkadot/types/primitive'
import { DecoderUtils } from '@kiltprotocol/utils'
Expand All @@ -51,7 +51,7 @@ export function decodeDelegationHierarchyDetails(
encoded: Option<IChainDelegationHierarchyDetails>
): DelegationHierarchyDetailsRecord | null {
DecoderUtils.assertCodecIsType(encoded, [
'Option<DelegationHierarchyDetails>',
'Option<DelegationDelegationHierarchyDelegationHierarchyDetails>',
])
if (encoded.isNone) {
return null
Expand Down Expand Up @@ -89,23 +89,29 @@ export type DelegationNodeId = Hash
export interface IChainDelegationNode extends Struct {
readonly hierarchyRootId: DelegationNodeId
readonly parent: Option<DelegationNodeId>
readonly children: BTreeSet<DelegationNodeId>
readonly children: Vec<DelegationNodeId>
readonly details: IChainDelegationDetails
readonly deposit: Deposit
}

type DelegationOwnerIdentifier = AccountId

interface IPermissions extends Struct {
bits: u32
}

export interface IChainDelegationDetails extends Struct {
readonly owner: DelegationOwnerIdentifier
readonly revoked: Bool
readonly permissions: u32
readonly permissions: IPermissions
}

export function decodeDelegationNode(
encoded: Option<IChainDelegationNode>
): DelegationNodeRecord | null {
DecoderUtils.assertCodecIsType(encoded, ['Option<DelegationNode>'])
DecoderUtils.assertCodecIsType(encoded, [
'Option<DelegationDelegationHierarchyDelegationNode>',
])
if (encoded.isNone) {
return null
}
Expand All @@ -116,13 +122,13 @@ export function decodeDelegationNode(
parentId: delegationNode.parent.isSome
? delegationNode.parent.toHex()
: undefined,
childrenIds: [...delegationNode.children.keys()].map((id) => id.toHex()),
childrenIds: [...delegationNode.children].map((id) => id.toHex()),
account: DidUtils.getKiltDidFromIdentifier(
delegationNode.details.owner.toString(),
'full'
),
permissions: decodePermissions(
delegationNode.details.permissions.toNumber()
delegationNode.details.permissions.bits.toNumber()
),
revoked: delegationNode.details.revoked.valueOf(),
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/delegation/DelegationNode.chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export async function getChildren(
* @internal
*/
function decodeDelegatedAttestations(queryResult: Option<Vec<Hash>>): string[] {
DecoderUtils.assertCodecIsType(queryResult, ['Option<Vec<ClaimHashOf>>'])
DecoderUtils.assertCodecIsType(queryResult, ['Option<Vec<H256>>'])
return queryResult.unwrapOrDefault().map((hash) => hash.toHex())
}

Expand Down
10 changes: 5 additions & 5 deletions packages/did/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
"@kiltprotocol/chain-helpers": "workspace:*",
"@kiltprotocol/types": "workspace:*",
"@kiltprotocol/utils": "workspace:*",
"@polkadot/api": "^5.4.1",
"@polkadot/keyring": "^7.1.2",
"@polkadot/types": "^5.4.1",
"@polkadot/util": "^7.1.2",
"@polkadot/util-crypto": "^7.1.2",
"@polkadot/api": "6.4.2",
"@polkadot/keyring": "7.5.1",
"@polkadot/types": "6.4.2",
"@polkadot/util": "7.5.1",
"@polkadot/util-crypto": "7.5.1",
"cbor": "^6.0.0"
}
}
8 changes: 4 additions & 4 deletions packages/did/src/Did.chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ function decodeDidChainRecord(
keyAgreementKeys: keyAgreementKeyIds,
lastTxCounter: didDetail.lastTxCounter,
}
if (didDetail.capabilityDelegationKey.isSome) {
if (didDetail.delegationKey.isSome) {
didRecord.capabilityDelegationKey = assembleKeyId(
didDetail.capabilityDelegationKey.unwrap(),
didDetail.delegationKey.unwrap(),
did
)
}
if (didDetail.assertionMethodKey.isSome) {
if (didDetail.attestationKey.isSome) {
didRecord.assertionMethodKey = assembleKeyId(
didDetail.assertionMethodKey.unwrap(),
didDetail.attestationKey.unwrap(),
did
)
}
Expand Down
11 changes: 5 additions & 6 deletions packages/did/src/Did.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,17 +239,16 @@ export function encodeDidCreationOperation(
did: didIdentifier,
submitter,
newKeyAgreementKeys: encryptionKey ? [formatPublicKey(encryptionKey)] : [],
newAssertionMethodKey: assertionMethodKey
newAttestationKey: assertionMethodKey
? formatPublicKey(assertionMethodKey)
: undefined,
newCapabilityDelegationKey: delegationKey
newDelegationKey: delegationKey
? formatPublicKey(delegationKey)
: undefined,
}
return new (registry.getOrThrow<DidCreationDetails>('DidCreationDetails'))(
registry,
didCreateRaw
)
return new (registry.getOrThrow<DidCreationDetails>(
'DidDidDetailsDidCreationDetails'
))(registry, didCreateRaw)
}

export function encodeDidAuthorizedCallOperation(
Expand Down
6 changes: 3 additions & 3 deletions packages/did/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ export type DidPublicKeyMap = BTreeMap<KeyId, DidPublicKeyDetails>
export interface IDidChainRecordCodec extends Struct {
authenticationKey: KeyId
keyAgreementKeys: DidKeyAgreementKeys
capabilityDelegationKey: Option<KeyId>
assertionMethodKey: Option<KeyId>
delegationKey: Option<KeyId>
attestationKey: Option<KeyId>
publicKeys: DidPublicKeyMap
lastTxCounter: u64
deposit: Deposit
Expand All @@ -153,7 +153,7 @@ export interface IDidChainRecordCodec extends Struct {
export interface DidCreationDetails extends Struct {
did: DidIdentifier
newKeyAgreementKeys: BTreeSet<DidEncryptionKey>
newAssertionMethodKey: Option<DidVerificationKey>
newAttestationKey: Option<DidVerificationKey>
newDelegationKey: Option<DidVerificationKey>
}

Expand Down
2 changes: 1 addition & 1 deletion packages/messaging/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
"@kiltprotocol/did": "workspace:*",
"@kiltprotocol/types": "workspace:*",
"@kiltprotocol/utils": "workspace:*",
"@polkadot/util": "^7.1.2"
"@polkadot/util": "7.5.1"
}
}
Loading