From fbeed978d260df988ca5b183d6b1ddf3d016cb1f Mon Sep 17 00:00:00 2001 From: Raphael Flechtner <39338561+rflechtner@users.noreply.github.com> Date: Tue, 13 Jun 2023 11:43:50 +0200 Subject: [PATCH] feat: re-export imported types from @kiltprotocol/types (#762) * feat: re-export imported types from @kiltprotocol/types * refactor: use re-exported types throughout sdk --- .../PublicCredentials.spec.ts | 2 +- packages/core/src/claim/Claim.ts | 9 +++++++-- .../publicCredential/PublicCredential.chain.ts | 2 +- .../src/publicCredential/PublicCredential.ts | 2 +- packages/did/src/Did.chain.ts | 2 +- packages/did/src/Did.rpc.ts | 3 ++- packages/did/src/DidLinks/AccountLinks.chain.ts | 9 ++++++--- packages/testing/src/metadata/spiritnet.ts | 2 +- packages/testing/src/mocks/typeRegistry.ts | 4 ++-- packages/types/src/Address.ts | 5 ++--- packages/types/src/Balance.ts | 3 +-- packages/types/src/CType.ts | 2 +- packages/types/src/Credential.ts | 2 +- packages/types/src/Deposit.ts | 2 +- packages/types/src/DidDocument.ts | 3 +-- packages/types/src/Imported.ts | 17 +++++++++++++++++ packages/types/src/Message.ts | 3 +-- packages/types/src/PublicCredential.ts | 4 +--- packages/types/src/index.ts | 5 +---- packages/utils/src/Crypto.ts | 4 ++-- 20 files changed, 51 insertions(+), 34 deletions(-) create mode 100644 packages/types/src/Imported.ts diff --git a/packages/core/src/__integrationtests__/PublicCredentials.spec.ts b/packages/core/src/__integrationtests__/PublicCredentials.spec.ts index 0b4f221a5..dfa42f056 100644 --- a/packages/core/src/__integrationtests__/PublicCredentials.spec.ts +++ b/packages/core/src/__integrationtests__/PublicCredentials.spec.ts @@ -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' diff --git a/packages/core/src/claim/Claim.ts b/packages/core/src/claim/Claim.ts index 58285a236..17aa1da54 100644 --- a/packages/core/src/claim/Claim.ts +++ b/packages/core/src/claim/Claim.ts @@ -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' diff --git a/packages/core/src/publicCredential/PublicCredential.chain.ts b/packages/core/src/publicCredential/PublicCredential.chain.ts index 4d635b596..046f3de73 100644 --- a/packages/core/src/publicCredential/PublicCredential.chain.ts +++ b/packages/core/src/publicCredential/PublicCredential.chain.ts @@ -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' @@ -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' diff --git a/packages/core/src/publicCredential/PublicCredential.ts b/packages/core/src/publicCredential/PublicCredential.ts index f28a865db..51e39482c 100644 --- a/packages/core/src/publicCredential/PublicCredential.ts +++ b/packages/core/src/publicCredential/PublicCredential.ts @@ -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, diff --git a/packages/did/src/Did.chain.ts b/packages/did/src/Did.chain.ts index 3880c141f..09daf45e4 100644 --- a/packages/did/src/Did.chain.ts +++ b/packages/did/src/Did.chain.ts @@ -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, @@ -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' diff --git a/packages/did/src/Did.rpc.ts b/packages/did/src/Did.rpc.ts index 4812a0cac..da77219d6 100644 --- a/packages/did/src/Did.rpc.ts +++ b/packages/did/src/Did.rpc.ts @@ -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' diff --git a/packages/did/src/DidLinks/AccountLinks.chain.ts b/packages/did/src/DidLinks/AccountLinks.chain.ts index ae62cbc60..882568d3b 100644 --- a/packages/did/src/DidLinks/AccountLinks.chain.ts +++ b/packages/did/src/DidLinks/AccountLinks.chain.ts @@ -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, @@ -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' diff --git a/packages/testing/src/metadata/spiritnet.ts b/packages/testing/src/metadata/spiritnet.ts index 341f1d6ea..1a319ed1d 100644 --- a/packages/testing/src/metadata/spiritnet.ts +++ b/packages/testing/src/metadata/spiritnet.ts @@ -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( diff --git a/packages/testing/src/mocks/typeRegistry.ts b/packages/testing/src/mocks/typeRegistry.ts index 457bc8773..a2aa7f1ae 100644 --- a/packages/testing/src/mocks/typeRegistry.ts +++ b/packages/testing/src/mocks/typeRegistry.ts @@ -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 diff --git a/packages/types/src/Address.ts b/packages/types/src/Address.ts index 57f1e320c..9ee9edfd5 100644 --- a/packages/types/src/Address.ts +++ b/packages/types/src/Address.ts @@ -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 diff --git a/packages/types/src/Balance.ts b/packages/types/src/Balance.ts index 6ea4ddcf8..a8381b130 100644 --- a/packages/types/src/Balance.ts +++ b/packages/types/src/Balance.ts @@ -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 diff --git a/packages/types/src/CType.ts b/packages/types/src/CType.ts index c0737de15..7ab4452f1 100644 --- a/packages/types/src/CType.ts +++ b/packages/types/src/CType.ts @@ -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' diff --git a/packages/types/src/Credential.ts b/packages/types/src/Credential.ts index e0f7e657c..ec2c0d467 100644 --- a/packages/types/src/Credential.ts +++ b/packages/types/src/Credential.ts @@ -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 diff --git a/packages/types/src/Deposit.ts b/packages/types/src/Deposit.ts index 01a5e6f74..6cc0a583c 100644 --- a/packages/types/src/Deposit.ts +++ b/packages/types/src/Deposit.ts @@ -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' /** diff --git a/packages/types/src/DidDocument.ts b/packages/types/src/DidDocument.ts index 61340a977..9bf9a7502 100644 --- a/packages/types/src/DidDocument.ts +++ b/packages/types/src/DidDocument.ts @@ -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' diff --git a/packages/types/src/Imported.ts b/packages/types/src/Imported.ts new file mode 100644 index 000000000..f83228443 --- /dev/null +++ b/packages/types/src/Imported.ts @@ -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' diff --git a/packages/types/src/Message.ts b/packages/types/src/Message.ts index ba2445d1f..b4264dc76 100644 --- a/packages/types/src/Message.ts +++ b/packages/types/src/Message.ts @@ -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' diff --git a/packages/types/src/PublicCredential.ts b/packages/types/src/PublicCredential.ts index 25451038b..0b3ba75db 100644 --- a/packages/types/src/PublicCredential.ts +++ b/packages/types/src/PublicCredential.ts @@ -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' diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index 81efc6583..16c6bf418 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -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' @@ -33,3 +29,4 @@ export * from './CryptoCallbacks.js' export * from './DidResolver.js' export * from './DidDocumentExporter.js' export * from './PublicCredential.js' +export * from './Imported.js' diff --git a/packages/utils/src/Crypto.ts b/packages/utils/src/Crypto.ts index 111f04997..5e493c438 100644 --- a/packages/utils/src/Crypto.ts +++ b/packages/utils/src/Crypto.ts @@ -15,8 +15,9 @@ import { decodeAddress, encodeAddress } from '@polkadot/keyring' import type { - KiltEncryptionKeypair, + HexString, KeyringPair, + KiltEncryptionKeypair, KiltKeyringPair, } from '@kiltprotocol/types' import { @@ -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'