Skip to content

Commit

Permalink
Mark ethers optional (#1124)
Browse files Browse the repository at this point in the history
* fix: optimize chat.list (#1115)

* fix: allow groupImage and groupDesc to be updated to null (#1118)

* fix: mark ethers as optional peer dependency

* fix: change typeDataDomain

* fix: update readme
  • Loading branch information
Aman035 authored Feb 26, 2024
1 parent e5f598e commit 523bfb8
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 1,425 deletions.
6 changes: 4 additions & 2 deletions packages/restapi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,17 @@ This package gives access to Push Protocol (Push Nodes) APIs. Visit [Developer D
## Installation

```bash
yarn add @pushprotocol/restapi@latest ethers
yarn add @pushprotocol/restapi@latest
```

or

```bash
npm install @pushprotocol/restapi@latest ethers
npm install @pushprotocol/restapi@latest
```

**Note** - ethers is an optional peer dependency and is required only when sdk is used with ethers signer.

## Import SDK

```typescript
Expand Down
6 changes: 5 additions & 1 deletion packages/restapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
"peerDependencies": {
"ethers": "^5.0.0 || ^6.0.0"
},
"peerDependenciesMeta": {
"ethers": {
"optional": true
}
},
"dependencies": {
"@ambire/signature-validator": "^1.3.1",
"@metamask/eth-sig-util": "^5.0.2",
"buffer": "^6.0.3",
"crypto-js": "^4.1.1",
Expand Down
17 changes: 0 additions & 17 deletions packages/restapi/src/lib/chat/helpers/signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,23 +145,6 @@ export const verifyProfileSignature = async (
} else return false;
} catch (err) {
return false;
// TODO - Add support for SCW Wallet

/**
* @todo - Add support for SCW Wallet
* @notice - verifyMessage does not work with EthersV6
*/
// try {
// const verificationResult: boolean = await verifyMessage({
// signer: address.toLowerCase(),
// message: signedData,
// signature: signature,
// provider: ethers.getDefaultProvider(1),
// });
// return verificationResult;
// } catch (err) {
// return false;
// }
}
}
};
2 changes: 1 addition & 1 deletion packages/restapi/src/lib/helpers/signer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SignerType, viemSignerType } from '../types';
import { TypedDataDomain, TypedDataField } from 'ethers';
import { TypedDataField, TypedDataDomain } from '../types';

export class Signer {
private signer: SignerType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
import * as config from '../config';
import { getAccountAddress } from '../chat/helpers';
import { IDENTITY_TYPE, NOTIFICATION_TYPE } from '../payloads/constants';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { ethers, Signer as EthersSigner } from 'ethers';
import {
createPublicClient,
Expand Down Expand Up @@ -457,7 +459,12 @@ export class PushNotificationBaseClass {
throw new Error('viem signer is not provided');
}
const createChannelPromise = contract.write.createChannelWithPUSH({
args: [channelType, toHex(new Uint8Array(identityBytes)), fees, this.getTimeBound()],
args: [
channelType,
toHex(new Uint8Array(identityBytes)),
fees,
this.getTimeBound(),
],
});
createChannelRes = await createChannelPromise;
}
Expand Down Expand Up @@ -818,4 +825,4 @@ export class PushNotificationBaseClass {
protected getAddressFromCaip(caipAddress: string): string {
return caipAddress?.split(':')[caipAddress?.split(':').length - 1];
}
}
}
37 changes: 25 additions & 12 deletions packages/restapi/src/lib/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// for namespace TYPES
/* eslint-disable @typescript-eslint/no-namespace */

import { TypedDataDomain, TypedDataField } from 'ethers';
import { ResolvedConfig } from 'viem';
import {
ADDITIONAL_META_TYPE,
IDENTITY_TYPE,
Expand Down Expand Up @@ -89,9 +88,9 @@ export type ParsedResponseType = {
};

export type ApiSubscriptionType = {
channel: string,
user_settings: string | null
}
channel: string;
user_settings: string | null;
};

export type NotificationSettingType = {
type: number;
Expand All @@ -103,17 +102,18 @@ export type NotificationSettingType = {
ticker?: number;
};
userPreferance?: {
value: number | { upper: number; lower: number },
enabled: boolean
}
value: number | { upper: number; lower: number };
enabled: boolean;
};
};

export type ApiSubscribersType = {
itemcount: number,
itemcount: number;
subscribers: {
subscriber: string, settings: string | null
}[]
}
subscriber: string;
settings: string | null;
}[];
};
export interface VideoNotificationRules {
access: {
type: VIDEO_NOTIFICATION_ACCESS_TYPE;
Expand Down Expand Up @@ -717,6 +717,19 @@ export interface UserInfo {
isAdmin: boolean;
}

export type TypedDataField = {
name: string;
type: string;
};

export type TypedDataDomain = {
chainId?: number | undefined;
name?: string | undefined;
salt?: ResolvedConfig['BytesType']['outputs'] | undefined;
verifyingContract?: string | undefined;
version?: string | undefined;
};

export type ethersV5SignerType = {
_signTypedData: (
domain: TypedDataDomain,
Expand Down
Loading

0 comments on commit 523bfb8

Please sign in to comment.