Skip to content

Commit

Permalink
feat: re-export imported types from @kiltprotocol/types (#762)
Browse files Browse the repository at this point in the history
* feat: re-export imported types from @kiltprotocol/types
* refactor: use re-exported types throughout sdk
  • Loading branch information
rflechtner authored Jun 13, 2023
1 parent 909b771 commit fbeed97
Show file tree
Hide file tree
Showing 20 changed files with 51 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
*/

import type { ApiPromise } from '@polkadot/api'
import type { HexString } from '@polkadot/util/types'
import type {
AssetDidUri,
DidDocument,
IPublicCredential,
IPublicCredentialInput,
KiltKeyringPair,
HexString,
} from '@kiltprotocol/types'

import { BN } from '@polkadot/util'
Expand Down
9 changes: 7 additions & 2 deletions packages/core/src/claim/Claim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@
*/

import { hexToBn } from '@polkadot/util'
import type { HexString } from '@polkadot/util/types'
import type { DidUri, IClaim, ICType, PartialClaim } from '@kiltprotocol/types'
import type {
DidUri,
IClaim,
ICType,
PartialClaim,
HexString,
} from '@kiltprotocol/types'
import { Crypto, DataUtils, SDKErrors } from '@kiltprotocol/utils'
import * as Did from '@kiltprotocol/did'
import * as CType from '../ctype/index.js'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
IPublicCredentialInput,
IPublicCredential,
DidUri,
HexString,
} from '@kiltprotocol/types'
import type { ApiPromise } from '@polkadot/api'
import type { GenericCall, Option } from '@polkadot/types'
Expand All @@ -24,7 +25,6 @@ import type {

import * as cbor from 'cbor-web'

import { HexString } from '@polkadot/util/types'
import { ConfigService } from '@kiltprotocol/config'
import { fromChain as didFromChain } from '@kiltprotocol/did'
import { validateUri } from '@kiltprotocol/asset-did'
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/publicCredential/PublicCredential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
* found in the LICENSE file in the root directory of this source tree.
*/

import type { HexString } from '@polkadot/util/types'
import type { AccountId } from '@polkadot/types/interfaces'
import type { PublicCredentialsCredentialsCredential } from '@kiltprotocol/augment-api'
import type {
HexString,
DidUri,
IAssetClaim,
ICType,
Expand Down
2 changes: 1 addition & 1 deletion packages/did/src/Did.chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import type { Option } from '@polkadot/types'
import type { AccountId32, Extrinsic, Hash } from '@polkadot/types/interfaces'
import type { AnyNumber } from '@polkadot/types/types'
import { BN } from '@polkadot/util'

import type {
Deposit,
Expand All @@ -27,6 +26,7 @@ import type {
SubmittableExtrinsic,
UriFragment,
VerificationKeyRelationship,
BN,
} from '@kiltprotocol/types'
import { verificationKeyTypes } from '@kiltprotocol/types'
import { Crypto, SDKErrors, ss58Format } from '@kiltprotocol/utils'
Expand Down
3 changes: 2 additions & 1 deletion packages/did/src/Did.rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ import type {
DidVerificationKey,
KiltAddress,
UriFragment,
BN,
} from '@kiltprotocol/types'

import { encodeAddress } from '@polkadot/keyring'
import { ethereumEncode } from '@polkadot/util-crypto'
import { BN, u8aToString } from '@polkadot/util'
import { u8aToString } from '@polkadot/util'
import { Crypto, ss58Format } from '@kiltprotocol/utils'

import { Address, SubstrateAddress } from './DidLinks/AccountLinks.chain.js'
Expand Down
9 changes: 6 additions & 3 deletions packages/did/src/DidLinks/AccountLinks.chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

import { decodeAddress, signatureVerify } from '@polkadot/util-crypto'
import type { TypeDef } from '@polkadot/types/types'
import type { HexString } from '@polkadot/util/types'
import type { KeyringPair } from '@polkadot/keyring/types'
import type { KeypairType } from '@polkadot/util-crypto/types'
import {
stringToU8a,
Expand All @@ -21,8 +19,13 @@ import {
import { ApiPromise } from '@polkadot/api'

import { SDKErrors } from '@kiltprotocol/utils'
import type { DidUri, KiltAddress } from '@kiltprotocol/types'
import { ConfigService } from '@kiltprotocol/config'
import type {
DidUri,
HexString,
KeyringPair,
KiltAddress,
} from '@kiltprotocol/types'

import { EncodedSignature } from '../Did.utils.js'
import { toChain } from '../Did.chain.js'
Expand Down
2 changes: 1 addition & 1 deletion packages/testing/src/metadata/spiritnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { readFileSync } from 'fs'
import path from 'path'
import type { HexString } from '@polkadot/util/types'
import type { HexString } from '@kiltprotocol/types'

const META_PATH = '../../../../augment-api/metadata/spiritnet.json'
const { result: metaHex } = JSON.parse(
Expand Down
4 changes: 2 additions & 2 deletions packages/testing/src/mocks/typeRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
// This module is not part of the public-facing api.
/* eslint-disable jsdoc/require-jsdoc */

import type { HexString } from '@polkadot/util/types'

import { ApiPromise, WsProvider } from '@polkadot/api'
import { Metadata, TypeRegistry } from '@polkadot/types'

import { types } from '@kiltprotocol/type-definitions'
import type { HexString } from '@kiltprotocol/types'

import metaStatic from '../metadata/spiritnet.js'

// adapted from https://github.com/polkadot-js/apps/blob/master/packages/test-support/src/api/createAugmentedApi.ts
Expand Down
5 changes: 2 additions & 3 deletions packages/types/src/Address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
* found in the LICENSE file in the root directory of this source tree.
*/

import type { Prefix } from '@polkadot/util-crypto/address/types'
import type { HexString } from '@polkadot/util/types'
import '@polkadot/keyring' // TS needs this for the augmentation below
import type { KeyringPair } from './index.js'

import type { HexString, KeyringPair, Prefix } from './Imported'

export interface KiltEncryptionKeypair {
secretKey: Uint8Array
Expand Down
3 changes: 1 addition & 2 deletions packages/types/src/Balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
* found in the LICENSE file in the root directory of this source tree.
*/

import type { AnyNumber } from '@polkadot/types/types/codec'
import type { BN } from '@polkadot/util'
import type { AnyNumber, BN } from './Imported'

export type Balances = {
free: BN
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/CType.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 type { HexString } from '@polkadot/util/types'
import type { HexString } from './Imported'

export type InstanceType = 'boolean' | 'integer' | 'number' | 'string' | 'array'

Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/Credential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
* found in the LICENSE file in the root directory of this source tree.
*/

import type { HexString } from '@polkadot/util/types'
import type { DidSignature } from './DidDocument'
import type { IClaim } from './Claim'
import type { IDelegationNode } from './Delegation'
import type { HexString } from './Imported'

export type Hash = HexString

Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/Deposit.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 type { BN } from '@polkadot/util'
import type { BN } from './Imported'
import type { KiltAddress } from './Address'

/**
Expand Down
3 changes: 1 addition & 2 deletions packages/types/src/DidDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
* found in the LICENSE file in the root directory of this source tree.
*/

import type { BN } from '@polkadot/util'

import type { BN } from './Imported'
import type { KiltAddress } from './Address'

type AuthenticationKeyType = '00' | '01'
Expand Down
17 changes: 17 additions & 0 deletions packages/types/src/Imported.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Copyright (c) 2018-2023, BOTLabs GmbH.
*
* This source code is licensed under the BSD 4-Clause "Original" license
* found in the LICENSE file in the root directory of this source tree.
*/

export type {
ISubmittableResult,
AnyNumber,
AnyJson,
} from '@polkadot/types/types'
export type { BN } from '@polkadot/util'
export type { HexString } from '@polkadot/util/types'
export type { Prefix } from '@polkadot/util-crypto/address/types'
export type { SubmittableExtrinsic } from '@polkadot/api/promise/types'
export type { KeyringPair } from '@polkadot/keyring/types'
3 changes: 1 addition & 2 deletions packages/types/src/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
* found in the LICENSE file in the root directory of this source tree.
*/

import type { AnyJson } from '@polkadot/types/types/codec'

import type { AnyJson } from './Imported'
import type { DidResourceUri, DidSignature, DidUri } from './DidDocument.js'
import type { IAttestation } from './Attestation.js'
import type { PartialClaim } from './Claim.js'
Expand Down
4 changes: 1 addition & 3 deletions packages/types/src/PublicCredential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
* found in the LICENSE file in the root directory of this source tree.
*/

import type { HexString } from '@polkadot/util/types'
import type { BN } from '@polkadot/util'

import type { HexString, BN } from './Imported'
import type { CTypeHash } from './CType'
import type { IDelegationNode } from './Delegation'
import type { IClaimContents } from './Claim'
Expand Down
5 changes: 1 addition & 4 deletions packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
* @module @kiltprotocol/types
*/

export type { ISubmittableResult } from '@polkadot/types/types'
export type { SubmittableExtrinsic } from '@polkadot/api/promise/types'
export type { KeyringPair } from '@polkadot/keyring/types'

export * as SubscriptionPromise from './SubscriptionPromise.js'

export * from './Attestation.js'
Expand All @@ -33,3 +29,4 @@ export * from './CryptoCallbacks.js'
export * from './DidResolver.js'
export * from './DidDocumentExporter.js'
export * from './PublicCredential.js'
export * from './Imported.js'
4 changes: 2 additions & 2 deletions packages/utils/src/Crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@

import { decodeAddress, encodeAddress } from '@polkadot/keyring'
import type {
KiltEncryptionKeypair,
HexString,
KeyringPair,
KiltEncryptionKeypair,
KiltKeyringPair,
} from '@kiltprotocol/types'
import {
Expand All @@ -36,7 +37,6 @@ import {
import { Keyring } from '@polkadot/api'
import nacl from 'tweetnacl'
import { v4 as uuid } from 'uuid'
import type { HexString } from '@polkadot/util/types'
import jsonabc from './jsonabc.js'
import * as SDKErrors from './SDKErrors.js'
import { ss58Format } from './ss58Format.js'
Expand Down

0 comments on commit fbeed97

Please sign in to comment.