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

refactor!: credentials package #791

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const common = {
'packages/types/',
'packages/augment-api/',
'packages/type-definitions/',
'packages/core/src/kilt/',
'packages/sdk-js/src/kilt/',
'index.ts',
'types.ts',
'.chain.ts',
Expand Down
2 changes: 1 addition & 1 deletion packages/asset-credentials/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"homepage": "https://github.com/KILTprotocol/sdk-js#readme",
"dependencies": {
"@kiltprotocol/config": "workspace:*",
"@kiltprotocol/core": "workspace:*",
"@kiltprotocol/credentials": "workspace:*",
"@kiltprotocol/did": "workspace:*",
"@kiltprotocol/types": "workspace:*",
"@kiltprotocol/utils": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { BN } from '@polkadot/util'

import { ConfigService } from '@kiltprotocol/config'
import { CType } from '@kiltprotocol/core'
import { CType } from '@kiltprotocol/credentials'
import * as Did from '@kiltprotocol/did'
import type {
AssetDidUri,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import type {
PartialAssetClaim,
} from '@kiltprotocol/types'

import { CType } from '@kiltprotocol/core'
import { CType } from '@kiltprotocol/credentials'
import { blake2AsHex } from '@polkadot/util-crypto'
import { ConfigService } from '@kiltprotocol/config'
import * as Did from '@kiltprotocol/did'
Expand Down
8 changes: 4 additions & 4 deletions packages/core/README.md → packages/credentials/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

![Lint and Test](https://github.com/KILTprotocol/sdk-js/workflows/Lint%20and%20Test/badge.svg)

# KILT Core
# KILT Credentials

This package provides the KILT credential core features and objects to make claims, build credentials and make attestations.
It also includes ctypes, quotes, delegations and balance utilities.
It also includes ctypes and delegations utilities.

For more information, please visit our [official SDK documentation](https://docs.kilt.io/docs/sdk/introduction).

Expand All @@ -15,11 +15,11 @@ For more information, please visit our [official SDK documentation](https://docs
NPM:

```
npm install @kiltprotocol/core
npm install @kiltprotocol/credentials
```

YARN:

```
yarn add @kiltprotocol/core
yarn add @kiltprotocol/credentials
```
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@kiltprotocol/core",
"name": "@kiltprotocol/credentials",
"version": "0.33.2-6",
"description": "",
"main": "./lib/cjs/index.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import {
import * as Attestation from '../attestation'
import * as Claim from '../claim'
import * as CType from '../ctype'
import { init } from '../kilt'
import * as Credential from './Credential'

const testCType = CType.fromProperties('Credential', {
Expand Down Expand Up @@ -75,7 +74,7 @@ beforeAll(async () => {
} as any)
),
} as any
await init({ api })
ConfigService.set({ api })
})

describe('Credential', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
*/

/**
* @module @kiltprotocol/core
* @module @kiltprotocol/credentials
*/

export * as Attestation from './attestation/index.js'
export * as Credential from './credential/index.js'
export { BalanceUtils } from './balance/index.js'
export * as Claim from './claim/index.js'
export * as CType from './ctype/index.js'
export { DelegationNode, DelegationNodeUtils } from './delegation/index.js'

export { connect, disconnect, init } from './kilt/index.js'
export { SDKErrors } from '@kiltprotocol/utils'
File renamed without changes.
8 changes: 6 additions & 2 deletions packages/sdk-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@
"dependencies": {
"@kiltprotocol/chain-helpers": "workspace:*",
"@kiltprotocol/config": "workspace:*",
"@kiltprotocol/core": "workspace:*",
"@kiltprotocol/credentials": "workspace:*",
"@kiltprotocol/did": "workspace:*",
"@kiltprotocol/type-definitions": "workspace:*",
"@kiltprotocol/types": "workspace:*",
"@kiltprotocol/utils": "workspace:*"
"@kiltprotocol/utils": "workspace:*",
"@polkadot/api": "^10.4.0",
"@polkadot/util": "^12.0.0",
"@polkadot/util-crypto": "^12.0.0"
}
}
4 changes: 3 additions & 1 deletion packages/sdk-js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
* @module @kiltprotocol/sdk-js
*/

export * from '@kiltprotocol/core'
export * from '@kiltprotocol/credentials'
export { ConfigService } from '@kiltprotocol/config'
export { Blockchain } from '@kiltprotocol/chain-helpers'
export * from './balance/index.js'
export * from './kilt/index.js'
export * as ChainHelpers from '@kiltprotocol/chain-helpers'
export * as Did from '@kiltprotocol/did'
export * as Utils from '@kiltprotocol/utils'
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/vc-export/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"dependencies": {
"@kiltprotocol/chain-helpers": "workspace:*",
"@kiltprotocol/config": "workspace:*",
"@kiltprotocol/core": "workspace:*",
"@kiltprotocol/credentials": "workspace:*",
"@kiltprotocol/did": "workspace:*",
"@kiltprotocol/types": "workspace:*",
"@kiltprotocol/utils": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/vc-export/src/CTypeVerification.spec.ts
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 { CType } from '@kiltprotocol/core'
import { CType } from '@kiltprotocol/credentials'
import { randomAsHex, randomAsU8a } from '@polkadot/util-crypto'
import {
attestation,
Expand Down
7 changes: 1 addition & 6 deletions packages/vc-export/src/DidJwt.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { hexToU8a } from '@polkadot/util'
import { ed25519PairFromSeed } from '@polkadot/util-crypto'
import type { Keypair } from '@polkadot/util-crypto/types'

import { init } from '@kiltprotocol/core'
import {
exportToDidDocument,
getFullDidUriFromKey,
Expand All @@ -22,8 +21,8 @@ import type {
} from '@kiltprotocol/types'

import * as JWT from './DidJwt'
import * as Presentation from './Presentation'
import { credentialSchema } from './KiltCredentialV1'
import * as Presentation from './Presentation'
import type { KiltCredentialV1 } from './types'

jest.mock('@kiltprotocol/did', () => ({
Expand Down Expand Up @@ -73,10 +72,6 @@ jest.mocked(resolveCompliant).mockImplementation(async (d) => {
}
})

beforeAll(async () => {
await init({})
})

it('produces and reverses JWT payload representations of a credential and presentation', () => {
const credential = {
'@context': [
Expand Down
2 changes: 1 addition & 1 deletion packages/vc-export/src/KiltAttestationProofV1.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { encodeAddress, randomAsHex, randomAsU8a } from '@polkadot/util-crypto'
import { u8aToHex, u8aToU8a } from '@polkadot/util'

import { Credential } from '@kiltprotocol/core'
import { Credential } from '@kiltprotocol/credentials'
import { parse } from '@kiltprotocol/did'
import type { DidUri } from '@kiltprotocol/types'

Expand Down
2 changes: 1 addition & 1 deletion packages/vc-export/src/KiltAttestationProofV1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import type {
} from '@polkadot/types/interfaces/types.js'
import type { IEventData, Signer } from '@polkadot/types/types'

import { CType } from '@kiltprotocol/core'
import { CType } from '@kiltprotocol/credentials'
import {
authorizeTx,
getFullDidUri,
Expand Down
2 changes: 1 addition & 1 deletion packages/vc-export/src/KiltCredentialV1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { hexToU8a } from '@polkadot/util'
import { base58Encode } from '@polkadot/util-crypto'

import { JsonSchema } from '@kiltprotocol/utils'
import { CType } from '@kiltprotocol/core'
import { CType } from '@kiltprotocol/credentials'
import type {
ICType,
ICredential,
Expand Down
2 changes: 1 addition & 1 deletion packages/vc-export/src/KiltRevocationStatusV1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { ApiPromise } from '@polkadot/api'
import type { U8aLike } from '@polkadot/util/types'

import { ConfigService } from '@kiltprotocol/config'
import { Attestation, CType, SDKErrors } from '@kiltprotocol/core'
import { Attestation, CType, SDKErrors } from '@kiltprotocol/credentials'
import type { Caip2ChainId } from '@kiltprotocol/types'

import { Caip2 } from './CAIP/index.js'
Expand Down
4 changes: 2 additions & 2 deletions packages/vc-export/src/Presentation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '@polkadot/util-crypto'
import type { Keypair } from '@polkadot/util-crypto/types'

import { init } from '@kiltprotocol/core'
import { ConfigService } from '@kiltprotocol/config'
import { getFullDidUri, getFullDidUriFromKey } from '@kiltprotocol/did'
import type {
DidDocument,
Expand Down Expand Up @@ -114,7 +114,7 @@ beforeAll(async () => {
api.query.did = {
didBlacklist: jest.fn().mockResolvedValue(api.createType('Option<Null>')),
} as any
await init({ api })
ConfigService.set({ api })
})

it('verifies a presentation signed by an ecdsa key', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { hexToU8a, u8aConcat, u8aToU8a } from '@polkadot/util'
import { randomAsU8a } from '@polkadot/util-crypto'

import { Credential } from '@kiltprotocol/core'
import { Credential } from '@kiltprotocol/credentials'
import type { IAttestation, ICType, ICredential } from '@kiltprotocol/types'

import { ApiMocks } from '../../../tests/testUtils'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import jsigs from 'jsonld-signatures' // cjs module
// @ts-expect-error not a typescript module
import jsonld from 'jsonld' // cjs module

import { Credential } from '@kiltprotocol/core'
import { Credential } from '@kiltprotocol/credentials'
import { ConfigService } from '@kiltprotocol/config'
import * as Did from '@kiltprotocol/did'
import { Crypto } from '@kiltprotocol/utils'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import jsigs from 'jsonld-signatures' // cjs module

import { ConfigService } from '@kiltprotocol/config'
import { CType } from '@kiltprotocol/core'
import { CType } from '@kiltprotocol/credentials'
import type { ICType } from '@kiltprotocol/types'

import { chainIdFromGenesis } from '../../CAIP/caip2.js'
Expand Down
10 changes: 4 additions & 6 deletions packages/vc-export/src/vc-js/suites/Sr25519Signature2020.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,24 @@
// @ts-expect-error not a typescript module
import * as vcjs from '@digitalbazaar/vc'

import { init } from '@kiltprotocol/core'
import * as Did from '@kiltprotocol/did'
import { Crypto } from '@kiltprotocol/utils'
import type {
ConformingDidDocument,
DidUri,
KiltKeyringPair,
} from '@kiltprotocol/types'
import { Crypto } from '@kiltprotocol/utils'

import { W3C_CREDENTIAL_CONTEXT_URL } from '../../constants.js'
import type { VerifiableCredential } from '../../types.js'
import {
combineDocumentLoaders,
kiltContextsLoader,
kiltDidLoader,
} from '../documentLoader.js'
import { W3C_CREDENTIAL_CONTEXT_URL } from '../../constants.js'
import ingosCredential from '../examples/ICredentialExample.json'
import { Sr25519Signature2020 } from './Sr25519Signature2020.js'
import { Sr25519VerificationKey2020 } from './Sr25519VerificationKey.js'
import ingosCredential from '../examples/ICredentialExample.json'
import type { VerifiableCredential } from '../../types.js'

// is not needed and imports a dependency that does not work in node 18
jest.mock('@digitalbazaar/http-client', () => ({}))
Expand All @@ -43,7 +42,6 @@ const documentLoader = combineDocumentLoaders([
])

export async function makeFakeDid() {
await init()
const keypair = Crypto.makeKeypairFromUri('//Ingo', 'sr25519')
const didDocument = Did.exportToDidDocument(
{
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/AccountLinking.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import { Keyring } from '@polkadot/keyring'
import { BN } from '@polkadot/util'
import { mnemonicGenerate } from '@polkadot/util-crypto'

import { BalanceUtils, disconnect } from '@kiltprotocol/core'
import * as Did from '@kiltprotocol/did'
import { BalanceUtils, Did, disconnect } from '@kiltprotocol/sdk-js'
import type {
DidDocument,
KeyringPair,
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/Attestation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import {
Claim,
Credential,
CType,
Did,
disconnect,
} from '@kiltprotocol/core'
import * as Did from '@kiltprotocol/did'
} from '@kiltprotocol/sdk-js'
import type {
DidDocument,
IAttestation,
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/Balance.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { jest } from '@jest/globals'
import { ApiPromise } from '@polkadot/api'
import { BN } from '@polkadot/util'

import { disconnect } from '@kiltprotocol/core'
import { disconnect } from '@kiltprotocol/sdk-js'
import type { KeyringPair } from '@kiltprotocol/types'

import { makeSigningKeyTool } from '../testUtils/index.js'
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/Blockchain.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import type { ApiPromise } from '@polkadot/api'
import { BN } from '@polkadot/util'

import { Blockchain } from '@kiltprotocol/chain-helpers'
import { BalanceUtils, disconnect } from '@kiltprotocol/core'
import { Blockchain, BalanceUtils, disconnect } from '@kiltprotocol/sdk-js'
import type { KeyringPair } from '@kiltprotocol/types'

import { makeSigningKeyTool } from '../testUtils/index.js'
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/Ctypes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

import type { ApiPromise } from '@polkadot/api'

import { CType, disconnect } from '@kiltprotocol/core'
import * as Did from '@kiltprotocol/did'
import { CType, Did, disconnect } from '@kiltprotocol/sdk-js'
import type { DidDocument, ICType, KiltKeyringPair } from '@kiltprotocol/types'
import { Crypto, UUID } from '@kiltprotocol/utils'

Expand Down
9 changes: 5 additions & 4 deletions tests/integration/Delegation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@ import {
Claim,
Credential,
DelegationNode,
Did,
disconnect,
} from '@kiltprotocol/core'
import * as Did from '@kiltprotocol/did'
import type {
} from '@kiltprotocol/sdk-js'
import {
DidDocument,
ICType,
IDelegationNode,
KiltKeyringPair,
Permission,
PermissionType,
SignCallback,
} from '@kiltprotocol/types'
import { Permission, PermissionType } from '@kiltprotocol/types'

import {
KeyTool,
Expand Down
5 changes: 3 additions & 2 deletions tests/integration/Deposit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import {
Claim,
Credential,
CType,
Did,
disconnect,
} from '@kiltprotocol/core'
import * as Did from '@kiltprotocol/did'
} from '@kiltprotocol/sdk-js'
import type {
DidDocument,
IAttestation,
Expand All @@ -25,6 +25,7 @@ import type {
SignCallback,
SubmittableExtrinsic,
} from '@kiltprotocol/types'

import {
createFullDidFromLightDid,
createFullDidFromSeed,
Expand Down
Loading