Skip to content

Commit

Permalink
[worker-api] move definition of isPubKeyPinPair to common (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
clangenb authored Sep 21, 2023
1 parent b5be931 commit 6c84e4d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
11 changes: 9 additions & 2 deletions packages/util/src/common.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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) {
Expand Down
9 changes: 0 additions & 9 deletions packages/worker-api/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions packages/worker-api/src/trustedCallApi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IEncointerWorker, PubKeyPinPair } from "./interface.js"
import type { IEncointerWorker } from "./interface.js"
import type {
BalanceTransferArgs, CommunityIdentifier,
GrantReputationArgs,
Expand All @@ -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);

Expand Down Expand Up @@ -39,4 +39,4 @@ export const createTrustedCall = (
nonce: nonce,
signature: toAccount(accountOrPubKey, self.keyring()).sign(payload)
});
}
}
4 changes: 2 additions & 2 deletions packages/worker-api/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 6c84e4d

Please sign in to comment.