Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
28a92f6
chore: update Delegation interfaces to match latest version
ntn-x2 Jul 28, 2021
6630e8c
feat: replace DelegationRoot with DelegationHierarchyDetails and Dele…
ntn-x2 Jul 28, 2021
2b51529
Merge branch 'develop' of github.com:KILTprotocol/sdk-js into aa-dele…
ntn-x2 Jul 28, 2021
6889f55
fix: fixing compilation errors (wip)
ntn-x2 Jul 28, 2021
09cefca
fix: more refactoring going on
ntn-x2 Jul 28, 2021
5a56f0a
feat: (wip) refactoring Delegation stuff
ntn-x2 Jul 28, 2021
93866e8
feat: add methods to store and retrieve root nodes
ntn-x2 Jul 29, 2021
f252704
test: unit tests passing
ntn-x2 Jul 29, 2021
3b92218
test: more unit tests
ntn-x2 Jul 29, 2021
639f902
test: first integration test passing
ntn-x2 Jul 29, 2021
2a06350
feat: refactor complete and ready for review
ntn-x2 Jul 30, 2021
c085506
fix: replace src with lib imports for tests
ntn-x2 Jul 30, 2021
dbfb335
fix: revert old port for integration tests
ntn-x2 Jul 30, 2021
0d9825a
fix: replace isNone with isNone for parent ID to HEX conversion
ntn-x2 Jul 30, 2021
8a20ab2
fix: hints from PR
ntn-x2 Aug 2, 2021
0578f3e
fix: apply remaining PR comments
ntn-x2 Aug 2, 2021
e8b1f49
feat: refactor delegation node creation input
ntn-x2 Aug 2, 2021
2c46809
feat: update delegation errors
ntn-x2 Aug 3, 2021
b1d15b6
fix: fix bug in refreshState()
ntn-x2 Aug 3, 2021
a6a5866
test: unit and integration tests now passing
ntn-x2 Aug 3, 2021
1e440c8
fix: rename refreshState() to getLatestState()
ntn-x2 Aug 3, 2021
23a9e1f
fix: test cases
ntn-x2 Aug 3, 2021
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
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ dist
lib
jest.*
coverage
*.d.ts
*.d.ts
4 changes: 2 additions & 2 deletions packages/actors_api/src/actors/Claimer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type {
IClaim,
IMessage,
IRequestAttestationForClaim,
IDelegationBaseNode,
IDelegationNode,
IPublicIdentity,
IRequestForAttestation,
} from '@kiltprotocol/types'
Expand Down Expand Up @@ -109,7 +109,7 @@ export function requestAttestation(
attesterPublicIdentity: IPublicIdentity,
option: {
legitimations?: AttestedClaim[]
delegationId?: IDelegationBaseNode['id']
delegationId?: IDelegationNode['id']
} = {}
): {
message: Message
Expand Down
2 changes: 1 addition & 1 deletion packages/chain-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"dependencies": {
"@kiltprotocol/config": "workspace:*",
"@kiltprotocol/type-definitions": "0.1.6",
"@kiltprotocol/type-definitions": "0.1.10",
"@kiltprotocol/types": "workspace:*",
"@kiltprotocol/utils": "workspace:*",
"@polkadot/api": "^4.13.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* found in the LICENSE file in the root directory of this source tree.
*/

import { types10 as KILT_TYPES } from '@kiltprotocol/type-definitions'
import { types17 as KILT_TYPES } from '@kiltprotocol/type-definitions'
import { TypeRegistry } from '@polkadot/types'

const TYPE_REGISTRY = new TypeRegistry()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@
* value setters `.mockReturnValue` or `.mockReturnValueOnce` on the method you want to modify:
* ```
* const mocked_api = require('../blockchainApiConnection/BlockchainApiConnection').__mocked_api
* mocked_api.query.delegation.children.mockReturnValue(
* new Vec(
* 'Hash',
* ['0x123', '0x456', '0x789']
* mocked_api.query.delegation.hierarchies.mockReturnValue(
* new Option(
* 'Hash'
* )
* )
* ```
Expand Down Expand Up @@ -229,10 +228,10 @@ const __mocked_api: any = {
}),
},
delegation: {
createRoot: jest.fn((rootId, _ctypeHash) => {
createHierarchy: jest.fn((rootId, _ctypeHash) => {
return __getMockSubmittableExtrinsic()
}),
revokeRoot: jest.fn((rootId) => {
addDelegation: jest.fn((delegationId, parent_id, owner, permissions, signature) => {
return __getMockSubmittableExtrinsic()
}),
revokeDelegation: jest.fn((delegationId) => {
Expand Down Expand Up @@ -305,18 +304,14 @@ const __mocked_api: any = {
},
delegation: {
// default return value decodes to null, represents delegation not found
roots: jest.fn(async (rootId: string) =>
mockChainQueryReturn('delegation', 'root')
hierarchies: jest.fn(async (rootId: string) =>
mockChainQueryReturn('delegation', 'hierarchies')
),
/* example return value:
new Option(
TYPE_REGISTRY,
Tuple.with(['Hash', AccountId, Bool]),
[
'0x1234', // ctype hash
'4r1WkS3t8rbCb11H8t3tJvGVCynwDXSUBiuGB6sLRHzCLCjs', // Account
false, // revoked flag
]
Hash,
'0x1234', // ctype hash
)
*/

Expand All @@ -327,28 +322,15 @@ const __mocked_api: any = {
/* example return value:
new Option(
TYPE_REGISTRY,
Tuple.with(['DelegationNodeId','Option<DelegationNodeId>',AccountId,U32,Bool]),
Tuple.with(['DelegationNodeId','Option<DelegationNodeId>','Vec<DelegationNodeId>',DelegationDetails]),
[
'0x1234', // root-id
null, // parent-id?
'4r1WkS3t8rbCb11H8t3tJvGVCynwDXSUBiuGB6sLRHzCLCjs', // Account
0, // permissions
false, // revoked flag
'0x1234', // root-id
'0x1234', // parent-id?
'[0x2345,0x3456] // children ids
'{4r1WkS3t8rbCb11H8t3tJvGVCynwDXSUBiuGB6sLRHzCLCjs,false,0}', // {owner, revocation status, permissions}
]
)
*/

// default return value decodes to [], represents: no children found
children: jest.fn(async (id: string) =>
mockChainQueryReturn('delegation', 'children')
),
/* example return value:
new Vec(
TYPE_REGISTRY,
'DelegationNodeId',
['0x123', '0x456', '0x789']
)
*/
},
did: {
// default return value decodes to null, represents dID not found
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const AccountId = TYPE_REGISTRY.getOrThrow('AccountId')
type ChainQueryTypes = {
attestation: 'attestations' | 'delegatedAttestations'
ctype: 'cTYPEs'
delegation: 'root' | 'delegations' | 'children'
delegation: 'hierarchies' | 'delegations'
did: 'dIDs'
portablegabi: 'accumulatorList' | 'accumulatorCount' | 'accountState'
}
Expand All @@ -34,16 +34,14 @@ const chainQueryReturnTuples: {
cTYPEs: AccountId,
},
delegation: {
// Root-Delegation: root-id -> (ctype-hash, account, revoked)
root: TYPE_REGISTRY.getOrUnknown('DelegationRoot'),
// Delegations: delegation-id -> (root-id, parent-id?, account, permissions, revoked)?
// Delegation hierarchies: root-id -> (ctype-hash)?
hierarchies: TYPE_REGISTRY.getOrUnknown('DelegationHierarchyDetails'),
// Delegations: delegation-id -> (hierarchy-id, parent-id?, childrenIds, details)?
delegations: TYPE_REGISTRY.getOrUnknown('DelegationNode'),
// Children: root-or-delegation-id -> [delegation-id]
children: TYPE_REGISTRY.getOrUnknown('DelegationNodeId'),
},
attestation: {
// Attestations: claim-hash -> (ctype-hash, attester-account, delegation-id?, revoked)?
attestations: TYPE_REGISTRY.getOrUnknown('Attestation'),
attestations: TYPE_REGISTRY.getOrUnknown('AttestationDetails'),
// DelegatedAttestations: delegation-id -> [claim-hash]
delegatedAttestations: TYPE_REGISTRY.getOrUnknown('Hash'),
},
Expand Down Expand Up @@ -116,7 +114,6 @@ export function mockChainQueryReturn<T extends keyof ChainQueryTypes>(
return wrapInOption()
}
case 'delegation': {
if (innerQuery === 'children') return wrapInVec()
return wrapInOption()
}
case 'did': {
Expand Down
67 changes: 49 additions & 18 deletions packages/chain-helpers/src/errorhandling/ExtrinsicError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,27 +80,53 @@ export const ExtrinsicErrors = {
code: 13002,
message: 'delegation not found',
},
ERROR_ROOT_ALREADY_EXISTS: { code: 13003, message: 'root already exist' },
ERROR_ROOT_NOT_FOUND: { code: 13004, message: 'root not found' },
ERROR_DELEGATE_NOT_FOUND: {
code: 13003,
message: 'delegate not found',
},
ERROR_HIERARCHY_ALREADY_EXISTS: {
code: 13004,
message: 'hierarchy already exist',
},
ERROR_HIERARCHY_NOT_FOUND: { code: 13005, message: 'hierarchy not found' },
ERROR_MAX_DELEGATION_SEARCH_DEPTH_REACHED: {
code: 13005,
code: 13006,
message: 'maximum delegation search depth reached',
},
ERROR_NOT_OWNER_OF_PARENT: { code: 13006, message: 'not owner of parent' },
ERROR_NOT_OWNER_OF_ROOT: { code: 13007, message: 'not owner of root' },
ERROR_PARENT_NOT_FOUND: { code: 13008, message: 'parent not found' },
ERROR_NOT_OWNER_OF_PARENT: { code: 13007, message: 'not owner of parent' },
ERROR_NOT_OWNER_OF_HIERARCHY: {
code: 13008,
message: 'not owner of hierarchy',
},
ERROR_PARENT_NOT_FOUND: { code: 13009, message: 'parent not found' },
ERROR_PARENT_REVOKED: {
code: 13010,
message: 'parent delegation revoked',
},
ERROR_NOT_PERMITTED_TO_REVOKE: {
code: 13009,
code: 13011,
message: 'not permitted to revoke',
},
ERROR_NOT_AUTHORIZED_TO_DELEGATE: {
code: 13010,
code: 13012,
message: 'not authorized to delegate',
},
ERROR_EXCEEDED_REVOCATION_BOUNDS: {
code: 13011,
code: 13013,
message: 'exceeded revocation bounds',
},
ERROR_EXCEEDED_MAX_REVOCATIONS_ALLOWED: {
code: 13014,
message: 'exceeded max revocations allowed',
},
ERROR_EXCEEDED_MAX_PARENT_CHECKS_ALLOWED: {
code: 13015,
message: 'exceeded max parent checks allowed',
},
INTERNAL_ERROR: {
code: 13016,
message: 'an internal delegation module error occured',
},
UNKNOWN_ERROR: {
code: 13100,
message: 'an unknown delegation module error occured',
Expand Down Expand Up @@ -163,15 +189,20 @@ export const PalletToExtrinsicErrors: IPalletToExtrinsicErrors = {
0: ExtrinsicErrors.Delegation.ERROR_DELEGATION_ALREADY_EXISTS,
1: ExtrinsicErrors.Delegation.ERROR_BAD_DELEGATION_SIGNATURE,
2: ExtrinsicErrors.Delegation.ERROR_DELEGATION_NOT_FOUND,
3: ExtrinsicErrors.Delegation.ERROR_ROOT_ALREADY_EXISTS,
4: ExtrinsicErrors.Delegation.ERROR_ROOT_NOT_FOUND,
5: ExtrinsicErrors.Delegation.ERROR_MAX_DELEGATION_SEARCH_DEPTH_REACHED,
6: ExtrinsicErrors.Delegation.ERROR_NOT_OWNER_OF_PARENT,
7: ExtrinsicErrors.Delegation.ERROR_NOT_OWNER_OF_ROOT,
8: ExtrinsicErrors.Delegation.ERROR_PARENT_NOT_FOUND,
9: ExtrinsicErrors.Delegation.ERROR_NOT_PERMITTED_TO_REVOKE,
10: ExtrinsicErrors.Delegation.ERROR_NOT_AUTHORIZED_TO_DELEGATE,
11: ExtrinsicErrors.Delegation.ERROR_EXCEEDED_REVOCATION_BOUNDS,
3: ExtrinsicErrors.Delegation.ERROR_DELEGATE_NOT_FOUND,
4: ExtrinsicErrors.Delegation.ERROR_HIERARCHY_ALREADY_EXISTS,
5: ExtrinsicErrors.Delegation.ERROR_HIERARCHY_NOT_FOUND,
6: ExtrinsicErrors.Delegation.ERROR_MAX_DELEGATION_SEARCH_DEPTH_REACHED,
7: ExtrinsicErrors.Delegation.ERROR_NOT_OWNER_OF_PARENT,
8: ExtrinsicErrors.Delegation.ERROR_NOT_OWNER_OF_HIERARCHY,
9: ExtrinsicErrors.Delegation.ERROR_PARENT_NOT_FOUND,
10: ExtrinsicErrors.Delegation.ERROR_PARENT_REVOKED,
11: ExtrinsicErrors.Delegation.ERROR_NOT_PERMITTED_TO_REVOKE,
12: ExtrinsicErrors.Delegation.ERROR_NOT_AUTHORIZED_TO_DELEGATE,
13: ExtrinsicErrors.Delegation.ERROR_EXCEEDED_REVOCATION_BOUNDS,
14: ExtrinsicErrors.Delegation.ERROR_EXCEEDED_MAX_REVOCATIONS_ALLOWED,
15: ExtrinsicErrors.Delegation.ERROR_EXCEEDED_MAX_PARENT_CHECKS_ALLOWED,
16: ExtrinsicErrors.Delegation.INTERNAL_ERROR,
[-1]: ExtrinsicErrors.Delegation.UNKNOWN_ERROR,
},
[PalletIndex.DID]: {
Expand Down
Loading