Skip to content

Commit 5066a9f

Browse files
committed
Merge branch 'fix/walletconnect-fix' into 'develop'
fix/walletconnect-fix See merge request papers/airgap/airgap-wallet!734
2 parents d48394c + 6d535e4 commit 5066a9f

File tree

4 files changed

+83
-25
lines changed

4 files changed

+83
-25
lines changed

src/app/pages/walletconnect/handler/walletconnect-v2.handler.ts

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ export class WalletconnectV2Handler implements WalletconnectHandler<Walletconnec
6363
}
6464

6565
// eslint-disable-next-line prettier/prettier
66-
const requiredEthNamespace: Web3WalletTypes.SessionProposal['params']['requiredNamespaces'][string] =
67-
(proposal.params.requiredNamespaces ?? {})[Namespace.ETH] ?? { methods: [], events: [] }
66+
const requiredEthNamespace: Web3WalletTypes.SessionProposal['params']['requiredNamespaces'][string] = (proposal.params
67+
.requiredNamespaces ?? {})[Namespace.ETH] ?? { methods: [], events: [] }
6868
// eslint-disable-next-line prettier/prettier
69-
const optionalEthNamespace: Web3WalletTypes.SessionProposal['params']['optionalNamespaces'][string] =
70-
(proposal.params.optionalNamespaces ?? {})[Namespace.ETH] ?? { methods: [], events: [] }
69+
const optionalEthNamespace: Web3WalletTypes.SessionProposal['params']['optionalNamespaces'][string] = (proposal.params
70+
.optionalNamespaces ?? {})[Namespace.ETH] ?? { methods: [], events: [] }
7171

7272
// for now, let's use the selected account for all required chains
7373
if (ethAccounts.length === 1) {
@@ -147,12 +147,54 @@ export class WalletconnectV2Handler implements WalletconnectHandler<Walletconnec
147147
case EthMethods.WALLET_SWITCH_ETHEREUM_CHAIN:
148148
return this.readWalletSwitchEthereumChain(request, client)
149149
case EthMethods.ETH_SIGN_TYPED_DATA:
150-
return { type: 'unsupported', namespace: Namespace.ETH, method: EthMethods.ETH_SIGN_TYPED_DATA }
150+
case EthMethods.ETH_SIGN_TYPED_DATA_V3:
151+
case EthMethods.ETH_SIGN_TYPED_DATA_V4:
152+
return this.readEthSignTypedData(request, client)
153+
case EthMethods.ETH_SIGN:
154+
return this.readEthSign(request, client)
155+
// return { type: 'unsupported', namespace: Namespace.ETH, method: EthMethods.ETH_SIGN_TYPED_DATA }
151156
default:
152157
return { type: 'unsupported', namespace: Namespace.ETH }
153158
}
154159
}
155160

161+
private readEthSign(request: Web3WalletTypes.SessionRequest, client: V2Client): WalletconnectMessage {
162+
request.params.request.params = [request.params.request.params[1], request.params.request.params[0]]
163+
return {
164+
type: 'signRequest',
165+
version: 2,
166+
namespace: Namespace.ETH,
167+
chain: request.params.chainId,
168+
request: {
169+
id: `${request.id}:${request.topic}`,
170+
method: EthMethods.ETH_SIGN,
171+
params: request.params.request.params
172+
},
173+
cancel: async (): Promise<void> => {
174+
rejectRequest(client, request.id, request.topic)
175+
}
176+
}
177+
}
178+
179+
private readEthSignTypedData(request: Web3WalletTypes.SessionRequest, client: V2Client): WalletconnectMessage {
180+
request.params.request.params = [request.params.request.params[1], request.params.request.params[0]]
181+
182+
return {
183+
type: 'signRequest',
184+
version: 2,
185+
namespace: Namespace.ETH,
186+
chain: request.params.chainId,
187+
request: {
188+
id: `${request.id}:${request.topic}`,
189+
method: EthMethods.ETH_SIGN_TYPED_DATA,
190+
params: request.params.request.params
191+
},
192+
cancel: async (): Promise<void> => {
193+
rejectRequest(client, request.id, request.topic)
194+
}
195+
}
196+
}
197+
156198
private readEthSendTransaction(request: Web3WalletTypes.SessionRequest, client: V2Client): WalletconnectMessage {
157199
return {
158200
type: 'signRequest',

src/app/pages/walletconnect/walletconnect.page.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
</div>
3030
</div>
3131

32-
<div *ngIf="mode === Mode.SIGN_MESSAGE">
32+
<div *ngIf="mode === Mode.SIGN_MESSAGE || mode === Mode.ETH_SIGN_TYPED_DATA || mode === Mode.ETH_SIGN">
3333
<ion-row class="rawdata--container">
3434
<ion-col class="ion-no-padding">
3535
<pre class="ion-no-margin">{{ beaconRequest | json }}</pre>

src/app/pages/walletconnect/walletconnect.page.ts

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ enum Mode {
4040
PERMISSION_REQUEST = 'permissionRequest',
4141
SIGN_TRANSACTION = 'signTransaction',
4242
SIGN_MESSAGE = 'signMessage',
43-
SWITCH_ACCOUNT = 'switchAccount'
43+
SWITCH_ACCOUNT = 'switchAccount',
44+
ETH_SIGN_TYPED_DATA = 'eth_signTypedData',
45+
ETH_SIGN = 'eth_sign'
4446
}
4547

4648
@Component({
@@ -137,24 +139,35 @@ export class WalletconnectPage implements OnInit {
137139
await this.permissionRequest(this.message)
138140
}
139141

140-
if (
141-
this.message.type === 'signRequest' &&
142-
this.message.namespace === Namespace.ETH &&
143-
this.message.request.method === EthMethods.ETH_SENDTRANSACTION
144-
) {
145-
this.mode = Mode.SIGN_TRANSACTION
146-
this.title = this.translateService.instant('walletconnect.new_transaction')
147-
await this.operationRequest(this.message as WalletconnectSignRequest<EthTx>)
148-
}
142+
if (this.message.type === 'signRequest' && this.message.namespace === Namespace.ETH) {
143+
if (this.message.request.method === EthMethods.ETH_SENDTRANSACTION) {
144+
this.mode = Mode.SIGN_TRANSACTION
145+
this.title = this.translateService.instant('walletconnect.new_transaction')
146+
await this.operationRequest(this.message as WalletconnectSignRequest<EthTx>)
147+
}
149148

150-
if (
151-
this.message.type === 'signRequest' &&
152-
this.message.namespace === Namespace.ETH &&
153-
this.message.request.method === EthMethods.PERSONAL_SIGN_REQUEST
154-
) {
155-
this.mode = Mode.SIGN_MESSAGE
156-
this.title = this.translateService.instant('walletconnect.sign_request')
157-
await this.signRequest(this.message as WalletconnectSignRequest<string>)
149+
if (this.message.request.method === EthMethods.PERSONAL_SIGN_REQUEST) {
150+
this.mode = Mode.SIGN_MESSAGE
151+
this.title = this.translateService.instant('walletconnect.sign_request')
152+
await this.signRequest(this.message as WalletconnectSignRequest<string>)
153+
}
154+
155+
if (this.message.request.method === EthMethods.PERSONAL_SIGN_REQUEST) {
156+
this.mode = Mode.SIGN_MESSAGE
157+
this.title = this.translateService.instant('walletconnect.sign_request')
158+
await this.signRequest(this.message as WalletconnectSignRequest<string>)
159+
}
160+
161+
if (this.message.request.method === EthMethods.ETH_SIGN_TYPED_DATA) {
162+
this.mode = Mode.ETH_SIGN_TYPED_DATA
163+
this.title = this.translateService.instant('walletconnect.sign_request')
164+
await this.signRequest(this.message as WalletconnectSignRequest<string>)
165+
}
166+
if (this.message.request.method === EthMethods.ETH_SIGN) {
167+
this.mode = Mode.ETH_SIGN
168+
this.title = this.translateService.instant('walletconnect.sign_request')
169+
await this.signRequest(this.message as WalletconnectSignRequest<string>)
170+
}
158171
}
159172

160173
if (

src/app/pages/walletconnect/walletconnect.types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ export enum EthMethods {
7474
ETH_SENDTRANSACTION = 'eth_sendTransaction',
7575
PERSONAL_SIGN_REQUEST = 'personal_sign',
7676
ETH_SIGN_TYPED_DATA = 'eth_signTypedData',
77-
WALLET_SWITCH_ETHEREUM_CHAIN = 'wallet_switchEthereumChain'
77+
ETH_SIGN_TYPED_DATA_V3 = 'eth_signTypedData_v3',
78+
ETH_SIGN_TYPED_DATA_V4 = 'eth_signTypedData_v4',
79+
WALLET_SWITCH_ETHEREUM_CHAIN = 'wallet_switchEthereumChain',
80+
ETH_SIGN = 'eth_sign'
7881
}
7982

8083
export interface EthTx {

0 commit comments

Comments
 (0)