Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
zzcwoshizz committed Mar 16, 2023
1 parent d284e3a commit 49e67aa
Show file tree
Hide file tree
Showing 19 changed files with 41 additions and 154 deletions.
7 changes: 1 addition & 6 deletions packages/contracts-core/src/ERC1155.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ import { BaseContract } from './base';
import { callMethod } from './utils';

class ERC1155 extends BaseContract {
constructor(
address: string,
provider: JsonRpcProvider,
abi = abis.ERC1155,
account?: string | null
) {
constructor(address: string, provider: JsonRpcProvider, abi = abis.ERC1155, account?: string | null) {
super(address, provider, abi, account);
}

Expand Down
9 changes: 2 additions & 7 deletions packages/contracts-core/src/KiltProofs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,9 @@ class KiltProofs extends BaseContract {
callback?: (exists: boolean) => void
): Promise<boolean> | Promise<() => void> {
if (callback) {
return this.web3Query.one<boolean>(
this.multicallContract.single_proof_exists(who, requestHash),
callback
);
return this.web3Query.one<boolean>(this.multicallContract.single_proof_exists(who, requestHash), callback);
} else {
return this.web3Query.one<boolean>(
this.multicallContract.single_proof_exists(who, requestHash)
);
return this.web3Query.one<boolean>(this.multicallContract.single_proof_exists(who, requestHash));
}
}

Expand Down
6 changes: 1 addition & 5 deletions packages/contracts-core/src/Poap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import type { BigNumber, BigNumberish } from '@ethersproject/bignumber';
import type {
JsonRpcProvider,
TransactionReceipt,
TransactionResponse
} from '@ethersproject/providers';
import type { JsonRpcProvider, TransactionReceipt, TransactionResponse } from '@ethersproject/providers';

import * as abis from './abis';
import { ERC1155 } from './ERC1155';
Expand Down
11 changes: 2 additions & 9 deletions packages/contracts-core/src/SimpleAggregator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,15 @@ class SimpleAggregator extends BaseContract {
}

public isFinished(cOwner: string, requestHash: BytesLike): Promise<boolean>;
public isFinished(
cOwner: string,
requestHash: BytesLike,
callback: (exists: boolean) => void
): Promise<() => void>;
public isFinished(cOwner: string, requestHash: BytesLike, callback: (exists: boolean) => void): Promise<() => void>;

public isFinished(
cOwner: string,
requestHash: BytesLike,
callback?: (exists: boolean) => void
): Promise<boolean> | Promise<() => void> {
if (callback) {
return this.web3Query.one<boolean>(
this.multicallContract.isFinished(cOwner, requestHash),
callback
);
return this.web3Query.one<boolean>(this.multicallContract.isFinished(cOwner, requestHash), callback);
} else {
return this.web3Query.one<boolean>(this.multicallContract.isFinished(cOwner, requestHash));
}
Expand Down
24 changes: 5 additions & 19 deletions packages/contracts-core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,7 @@ export function getProviderOrSigner(

// account is optional
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export function getContract(
address: string,
ABI: any,
library: JsonRpcProvider,
account?: string | null
): Contract {
export function getContract(address: string, ABI: any, library: JsonRpcProvider, account?: string | null): Contract {
if (!isAddress(address) || address === AddressZero) {
throw Error(`Invalid 'address' parameter '${address}'.`);
}
Expand Down Expand Up @@ -92,11 +87,7 @@ export async function getGasEstimate(
.catch((error: any) => {
console.debug('Call threw error', error);

return new CallError(
methodName,
'Call threw error',
error?.error?.data?.message || 'Unknown error'
);
return new CallError(methodName, 'Call threw error', error?.error?.data?.message || 'Unknown error');
});
});

Expand Down Expand Up @@ -126,8 +117,8 @@ export async function callMethod<T>(
// if the user rejected the tx, pass this along
if (
[
-32700, -32600, -32601, -32602, -32603, -32000, -32001, -32002, -32003, -32004, -32005,
-32006, 4001, 4100, 4200, 4900, 4901
-32700, -32600, -32601, -32602, -32603, -32000, -32001, -32002, -32003, -32004, -32005, -32006, 4001, 4100,
4200, 4900, 4901
].includes(error?.code)
) {
throw new RpcError(error.code);
Expand All @@ -142,11 +133,6 @@ export async function callMethod<T>(
export function getRequestHash(requestDetails: RequestDetails) {
return keccak256(
['bytes32', 'uint128[]', 'bytes32', 'bytes32'],
[
requestDetails.cType,
requestDetails.fieldNames,
requestDetails.programHash,
requestDetails.attester
]
[requestDetails.cType, requestDetails.fieldNames, requestDetails.programHash, requestDetails.attester]
);
}
20 changes: 6 additions & 14 deletions packages/credential-core/src/vc/encryptDecrypt.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,9 @@ describe('encrypt and decrypt', () => {
'0x887a133dfbc4741d71fcb882443f7260c3405f5a46c62a24ec3327ab1b72fad1'
],
claimNonceMap: {
'0xa7c77ad182242fb339b5c2298a5261b0a422689bb6114b2450c21b0d01e41ce8':
'8d583499-4dd0-4438-ad0e-91427f2c6213',
'0x73cf049941ed8805d3d1bf8a553f9004b91f28bfb45dd00ba22a9b8869fe2e67':
'4b270eb2-7b62-4173-b46d-c95af345d704',
'0x42db520aad41fb03d1aebd0afe4828e52c147000f93c1aa3331ccf8ff567cdbb':
'c87ac94c-5be7-4b60-8973-9b9849807f63'
'0xa7c77ad182242fb339b5c2298a5261b0a422689bb6114b2450c21b0d01e41ce8': '8d583499-4dd0-4438-ad0e-91427f2c6213',
'0x73cf049941ed8805d3d1bf8a553f9004b91f28bfb45dd00ba22a9b8869fe2e67': '4b270eb2-7b62-4173-b46d-c95af345d704',
'0x42db520aad41fb03d1aebd0afe4828e52c147000f93c1aa3331ccf8ff567cdbb': 'c87ac94c-5be7-4b60-8973-9b9849807f63'
},
legitimations: [],
delegationId: null,
Expand All @@ -53,9 +50,7 @@ describe('encrypt and decrypt', () => {
const decrypted = vcDecrypt(encrypted, '1234');

expect(decrypted).toEqual(kiltVC);
expect(() => vcDecrypt(encrypted, '123')).toThrow(
'Unable to decrypt using the supplied passphrase'
);
expect(() => vcDecrypt(encrypted, '123')).toThrow('Unable to decrypt using the supplied passphrase');
});

it('encrypt zkid vc and descrypt', () => {
Expand Down Expand Up @@ -92,8 +87,7 @@ describe('encrypt and decrypt', () => {
created: 1669915042670,
verificationMethod: 'did:zk:0xdC6BF231a4f18074288C07C3f31f2eD170E368aD#key-0',
proofPurpose: 'assertionMethod',
proofValue:
'zHghh8GGTZpQsMfbkaotA2XyKFT8QFY87sBbGGrQPtuyeBj86rMZK95LJ3WF9J7BHiffabpHsDbd64xoXc5AmLMskk'
proofValue: 'zHghh8GGTZpQsMfbkaotA2XyKFT8QFY87sBbGGrQPtuyeBj86rMZK95LJ3WF9J7BHiffabpHsDbd64xoXc5AmLMskk'
}
]
};
Expand All @@ -103,8 +97,6 @@ describe('encrypt and decrypt', () => {
const decrypted = vcDecrypt(encrypted, '1234');

expect(decrypted).toEqual(zkidVC);
expect(() => vcDecrypt(encrypted, '123')).toThrow(
'Unable to decrypt using the supplied passphrase'
);
expect(() => vcDecrypt(encrypted, '123')).toThrow('Unable to decrypt using the supplied passphrase');
});
});
12 changes: 2 additions & 10 deletions packages/did-keyring/src/DidManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,15 @@ export class DidManager extends DidBase<ZkidDidKeys$Json | KiltDidKeys$Json> {
this.kilt.on('remove', () => onRemove);
}

public override addDidFromMnemonic(
mnemonic: string,
password: string,
type: 'zk' | 'kilt' = 'zk'
): string {
public override addDidFromMnemonic(mnemonic: string, password: string, type: 'zk' | 'kilt' = 'zk'): string {
if (type === 'zk') {
return this.zk.addDidFromMnemonic(mnemonic, password);
} else {
return this.kilt.addDidFromMnemonic(mnemonic, password);
}
}

public override addDidFromJson(
json: ZkidDidKeys$Json | KiltDidKeys$Json,
newPass: string,
oldPass: string
): string {
public override addDidFromJson(json: ZkidDidKeys$Json | KiltDidKeys$Json, newPass: string, oldPass: string): string {
if (isZkDidKeys$Json(json)) {
return this.zk.addDidFromJson(json, newPass, oldPass);
}
Expand Down
4 changes: 1 addition & 3 deletions packages/did-keyring/src/kilt/Keyring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ export class Keyring extends PolkadotKeyring implements KiltKeystore {
data,
peerPublicKey,
publicKey
}: RequestData<A> & { peerPublicKey: Uint8Array }): Promise<
ResponseData<A> & { nonce: Uint8Array }
> {
}: RequestData<A> & { peerPublicKey: Uint8Array }): Promise<ResponseData<A> & { nonce: Uint8Array }> {
const pair = this.getPair(publicKey);

const nonce = randomAsU8a(24);
Expand Down
11 changes: 3 additions & 8 deletions packages/did-keyring/src/kilt/KiltDid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,12 @@ export class KiltDid extends DidBase<DidKeys$Json> {
* @returns a [[LightDidDetails]] object
*/
public override addDidFromMnemonic(mnemonic: string, password: string): DidUri {
const pairs = [
this.keyring.addFromUri(mnemonic, {}, 'sr25519'),
this.keyring.addFromUri(mnemonic, {}, 'ed25519')
];
const pairs = [this.keyring.addFromUri(mnemonic, {}, 'sr25519'), this.keyring.addFromUri(mnemonic, {}, 'ed25519')];

const didDetails = LightDidDetails.fromDetails({
authenticationKey: {
publicKey: pairs[0].publicKey,
type:
pairs[0].type === 'sr25519' ? VerificationKeyType.Sr25519 : VerificationKeyType.Ed25519
type: pairs[0].type === 'sr25519' ? VerificationKeyType.Sr25519 : VerificationKeyType.Ed25519
},
encryptionKey: {
publicKey: pairs[1].publicKey,
Expand All @@ -60,8 +56,7 @@ export class KiltDid extends DidBase<DidKeys$Json> {
const didDetails = LightDidDetails.fromDetails({
authenticationKey: {
publicKey: pairs[0].publicKey,
type:
pairs[0].type === 'sr25519' ? VerificationKeyType.Sr25519 : VerificationKeyType.Ed25519
type: pairs[0].type === 'sr25519' ? VerificationKeyType.Sr25519 : VerificationKeyType.Ed25519
},
encryptionKey: {
publicKey: pairs[1].publicKey,
Expand Down
7 changes: 1 addition & 6 deletions packages/did-keyring/src/kilt/types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
// Copyright 2021-2023 zcloak authors & contributors
// SPDX-License-Identifier: Apache-2.0

import type {
DidUri,
EncryptionAlgorithms,
Keystore,
SigningAlgorithms
} from '@kiltprotocol/types';
import type { DidUri, EncryptionAlgorithms, Keystore, SigningAlgorithms } from '@kiltprotocol/types';
import type { KeyringPair$Json } from '@polkadot/keyring/types';

export type KiltKeystore = Keystore<SigningAlgorithms, EncryptionAlgorithms>;
Expand Down
7 changes: 1 addition & 6 deletions packages/did-keyring/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
// Copyright 2021-2023 zcloak authors & contributors
// SPDX-License-Identifier: Apache-2.0

import type {
DidUri,
EncryptionAlgorithms,
Keystore,
SigningAlgorithms
} from '@kiltprotocol/types';
import type { DidUri, EncryptionAlgorithms, Keystore, SigningAlgorithms } from '@kiltprotocol/types';
import type { KeyringPair$Json as KiltKeyringPair$Json } from '@polkadot/keyring/types';
import type { DidKeys$Json } from '@zcloak/did/keys/types';

Expand Down
5 changes: 1 addition & 4 deletions packages/react-wallet/src/AbstractWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,5 @@ export abstract class AbstractWallet extends Events {

public abstract disconnect(): Promise<void>;

public abstract switchNetwork(
chainId: number,
params?: AddEthereumChainParameter
): Promise<boolean>;
public abstract switchNetwork(chainId: number, params?: AddEthereumChainParameter): Promise<boolean>;
}
10 changes: 2 additions & 8 deletions packages/react-wallet/src/WalletProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ interface Props {

const WalletContext = createContext<WalletState>({} as WalletState);

export const WalletProvider: React.FC<React.PropsWithChildren<Props>> = ({
children,
supportedChainId
}) => {
export const WalletProvider: React.FC<React.PropsWithChildren<Props>> = ({ children, supportedChainId }) => {
const [state, setState] = useState<WalletData>({});

const wallet = useRef<AbstractWallet>();
Expand All @@ -45,10 +42,7 @@ export const WalletProvider: React.FC<React.PropsWithChildren<Props>> = ({

setState((state) => ({
...state,
account:
_wallet.accounts && _wallet.accounts.length > 0
? getAddress(_wallet.accounts[0])
: undefined,
account: _wallet.accounts && _wallet.accounts.length > 0 ? getAddress(_wallet.accounts[0]) : undefined,
chainId: _wallet.chainId,
provider: _wallet.provider
}));
Expand Down
5 changes: 1 addition & 4 deletions packages/react-wallet/src/switchNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ export async function switchNetwork(
}
}

export async function addNetwork(
externalProvider: any,
params: AddEthereumChainParameter
): Promise<void> {
export async function addNetwork(externalProvider: any, params: AddEthereumChainParameter): Promise<void> {
await externalProvider?.request?.({
method: 'wallet_addEthereumChain',
params: [
Expand Down
16 changes: 4 additions & 12 deletions packages/service/src/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,9 @@ export class CredentialApi extends Request {
}

getAttestationStatus(params: { senderKeyId: string }) {
return this.get<ServerResponse<{ attestationStatus: AttestationStatus }>>(
'/admin-attester/attestation-status',
{
params
}
);
return this.get<ServerResponse<{ attestationStatus: AttestationStatus }>>('/admin-attester/attestation-status', {
params
});
}

getAttestation(params: { senderKeyId: string; receiverKeyId: string }) {
Expand Down Expand Up @@ -115,12 +112,7 @@ export class CredentialApi extends Request {
return this.post<ServerResponse<null>>('/message', { body });
}

getMessages(params: {
receiverKeyId?: string;
senderKeyId?: string;
start_id?: string;
size?: number;
}) {
getMessages(params: { receiverKeyId?: string; senderKeyId?: string; start_id?: string; size?: number }) {
return this.get<ServerResponse<(MessageBody & { id: string })[]>>('/message', { params });
}
}
5 changes: 1 addition & 4 deletions packages/ui-did-keyring/src/KiltDid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ export class KiltDid extends KiltDidSuper {
super.remove(didUrl);
}

public override addDid(
didUriOrDetails: DidUri | LightDidDetails,
password?: string | undefined
): LightDidDetails {
public override addDid(didUriOrDetails: DidUri | LightDidDetails, password?: string | undefined): LightDidDetails {
const didDetails = super.addDid(didUriOrDetails, password);

this.#store.set(kiltDidKey(didDetails.uri), didDetails.uri);
Expand Down
11 changes: 1 addition & 10 deletions packages/ui-did-keyring/src/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,4 @@ const zkPairKeyRegex = new RegExp(`^${ZK_PAIR_PREFIX}0x[0-9a-f]*`, '');
const zkDidKey = (didUri: DidUrl): string => didUri;
const zkDidRegex = new RegExp(`^${ZK_DID_PREFIX}0x[0-9A-Fa-f]*`, '');

export {
kiltPairKey,
kiltPairKeyRegex,
kiltDidKey,
kiltDidRegex,
zkPairKey,
zkPairKeyRegex,
zkDidKey,
zkDidRegex
};
export { kiltPairKey, kiltPairKeyRegex, kiltDidKey, kiltDidRegex, zkPairKey, zkPairKeyRegex, zkDidKey, zkDidRegex };
17 changes: 4 additions & 13 deletions packages/web3-query/src/Web3Query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ export class Web3Query {
}

public async all<T extends any[] = any[]>(calls: ContractCall[]): Promise<T>;
public async all<T extends any[] = any[]>(
calls: ContractCall[],
callback: (results: T) => void
): Promise<() => void>;
public async all<T extends any[] = any[]>(calls: ContractCall[], callback: (results: T) => void): Promise<() => void>;

public async all<T extends any[] = any[]>(
calls: ContractCall[],
Expand Down Expand Up @@ -99,15 +96,9 @@ export class Web3Query {
}

public async one<TOne = any>(call: ContractCall): Promise<TOne>;
public async one<TOne = any>(
call: ContractCall,
callback: (results: TOne) => void
): Promise<() => void>;

public async one<TOne = any>(
call: ContractCall,
callback?: (results: TOne) => void
): Promise<TOne | (() => void)> {
public async one<TOne = any>(call: ContractCall, callback: (results: TOne) => void): Promise<() => void>;

public async one<TOne = any>(call: ContractCall, callback?: (results: TOne) => void): Promise<TOne | (() => void)> {
const [result] = await all<[TOne]>([call], await getAddress(this._provider), this._provider);

if (callback) {
Expand Down
Loading

0 comments on commit 49e67aa

Please sign in to comment.