From 6c84e4d19f6c95d46ef7f030a472a4bde41f038d Mon Sep 17 00:00:00 2001 From: clangenb <37865735+clangenb@users.noreply.github.com> Date: Thu, 21 Sep 2023 10:40:12 +0200 Subject: [PATCH] [worker-api] move definition of `isPubKeyPinPair` to common (#82) --- packages/util/src/common.ts | 11 +++++++++-- packages/worker-api/src/interface.ts | 9 --------- packages/worker-api/src/trustedCallApi.ts | 6 +++--- packages/worker-api/src/worker.ts | 4 ++-- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/packages/util/src/common.ts b/packages/util/src/common.ts index eb54f679..6e1fa9e3 100644 --- a/packages/util/src/common.ts +++ b/packages/util/src/common.ts @@ -1,8 +1,6 @@ import assert from 'assert'; import type { KeyringPair } from "@polkadot/keyring/types"; -import type { PubKeyPinPair } from "@encointer/worker-api"; import { Keyring } from "@polkadot/keyring"; -import { isPubKeyPinPair } from "@encointer/worker-api/interface"; import BN from "bn.js"; interface assertLengthFunc { @@ -17,6 +15,15 @@ export const assertLength: assertLengthFunc = function (upper, lower) { return len; }; +export interface PubKeyPinPair { + pubKey: string, + pin: string, +} + +export function isPubKeyPinPair(pair: KeyringPair | PubKeyPinPair) { + return (pair as PubKeyPinPair).pin !== undefined; +} + export const toAccount = (accountOrPubKey: (KeyringPair | PubKeyPinPair), keyring?: Keyring): KeyringPair => { if (isPubKeyPinPair(accountOrPubKey)) { if (keyring !== undefined) { diff --git a/packages/worker-api/src/interface.ts b/packages/worker-api/src/interface.ts index 663edc5c..03d1338b 100644 --- a/packages/worker-api/src/interface.ts +++ b/packages/worker-api/src/interface.ts @@ -17,15 +17,6 @@ export interface WorkerOptions { createWebSocket?: (url: string) => WebSocket; } -export interface PubKeyPinPair { - pubKey: string, - pin: string, -} - -export function isPubKeyPinPair(pair: KeyringPair | PubKeyPinPair) { - return (pair as PubKeyPinPair).pin !== undefined; -} - export interface TrustedGetterArgs { cid: string; account: KeyringPair; diff --git a/packages/worker-api/src/trustedCallApi.ts b/packages/worker-api/src/trustedCallApi.ts index aaa014b1..7bf1d2e8 100644 --- a/packages/worker-api/src/trustedCallApi.ts +++ b/packages/worker-api/src/trustedCallApi.ts @@ -1,4 +1,4 @@ -import type { IEncointerWorker, PubKeyPinPair } from "./interface.js" +import type { IEncointerWorker } from "./interface.js" import type { BalanceTransferArgs, CommunityIdentifier, GrantReputationArgs, @@ -9,7 +9,7 @@ import type { import type { KeyringPair } from "@polkadot/keyring/types"; import type { u32 } from "@polkadot/types"; import bs58 from "bs58"; -import { toAccount } from "@encointer/util/common"; +import { toAccount, PubKeyPinPair } from "@encointer/util/common"; export type TrustedCallArgs = (BalanceTransferArgs | RegisterParticipantArgs | RegisterAttestationsArgs | GrantReputationArgs); @@ -39,4 +39,4 @@ export const createTrustedCall = ( nonce: nonce, signature: toAccount(accountOrPubKey, self.keyring()).sign(payload) }); -} \ No newline at end of file +} diff --git a/packages/worker-api/src/worker.ts b/packages/worker-api/src/worker.ts index 75797ae6..24118c04 100644 --- a/packages/worker-api/src/worker.ts +++ b/packages/worker-api/src/worker.ts @@ -22,12 +22,12 @@ import type { SchedulerState, TrustedCallSigned } from '@encointer/types'; -import type { IEncointerWorker, WorkerOptions, CallOptions, PubKeyPinPair } from './interface.js'; +import type { IEncointerWorker, WorkerOptions, CallOptions } from './interface.js'; import { Request } from './interface.js'; import { parseBalance, parseNodeRSA } from './parsers.js'; import { callGetter } from './getterApi.js'; import { createTrustedCall } from "@encointer/worker-api/trustedCallApi"; -import { toAccount } from "@encointer/util/common"; +import { toAccount, PubKeyPinPair } from "@encointer/util/common"; const unwrapWorkerResponse = (self: IEncointerWorker, data: string) => { /// Unwraps the value that is wrapped in all the Options and encoding from the worker.