Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/core/src/types/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ export interface SignOptions {
readonly disableBalanceCheck?: boolean;
}

export interface WCWalletOptions {
/**
* Expiry for WalletConnect signing requests, in seconds.
* Must be between 300 (5 minutes) and 604800 (7 days).
* @see https://specs.walletconnect.com/2.0/specs/clients/sign/rpc-methods#expiry-validation
*/
signingRequestExpiry?: number;
}

export type Algo = 'secp256k1' | 'eth_secp256k1';
export interface AccountData {
/** A printable address (typically bech32 encoded) */
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/wallets/wc-wallets/wc-cosmos-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export class WCCosmosWallet extends CosmosWallet implements IWCCommon {
signerAddress: signer,
signDoc,
},
}, `cosmos:${chainId}`);
}, `cosmos:${chainId}`, this.wcWallet?.options?.signingRequestExpiry);

return result as AminoSignResponse;
} catch (error) {
Expand Down Expand Up @@ -152,7 +152,7 @@ export class WCCosmosWallet extends CosmosWallet implements IWCCommon {
const result = await (this.provider.request({
method: 'cosmos_signDirect',
params: signDocValue,
}, `cosmos:${chainId}`) as Promise<WCDirectSignResponse>);
}, `cosmos:${chainId}`, this.wcWallet?.options?.signingRequestExpiry) as Promise<WCDirectSignResponse>);

return {
signed: {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/wallets/wc-wallets/wc-ethereum-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class WCEthereumWallet extends EthereumWallet implements IWCCommon {
const result = await this.provider.request({
method: 'eth_sendTransaction',
params: [transactionParameters]
}) as string;
}, undefined, this.wcWallet?.options?.signingRequestExpiry) as string;
return result;
} catch (error) {
console.log('send transaction error:', error);
Expand All @@ -126,7 +126,7 @@ export class WCEthereumWallet extends EthereumWallet implements IWCCommon {
const result = await this.provider.request({
method: 'personal_sign',
params: [message]
}) as string;
}, undefined, this.wcWallet?.options?.signingRequestExpiry) as string;
return result;
} catch (error) {
console.log('sign message error:', error);
Expand Down
11 changes: 6 additions & 5 deletions packages/core/src/wallets/wc-wallets/wc-solana-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class WCSolanaWallet extends SolanaWallet implements IWCCommon {
const result = await this.provider.request({
method: 'solana_signAllTransactions',
params: { transactions }
}) as any[];
}, undefined, this.wcWallet?.options?.signingRequestExpiry) as any[];
return result;
} catch (error) {
console.log('sign all transactions error:', error);
Expand All @@ -135,7 +135,7 @@ export class WCSolanaWallet extends SolanaWallet implements IWCCommon {
const result = await this.provider.request({
method: 'solana_signAndSendAllTransactions',
params: { transactions }
});
}, undefined, this.wcWallet?.options?.signingRequestExpiry);
return result;
} catch (error) {
console.log('sign and send all transactions error:', error);
Expand All @@ -154,7 +154,7 @@ export class WCSolanaWallet extends SolanaWallet implements IWCCommon {
params: {
transaction: transaction.serialize({ verifySignatures: false }).toString('base64')
}
}) as string;
}, undefined, this.wcWallet?.options?.signingRequestExpiry) as string;
return result;
} catch (error) {
console.log('sign and send transaction error:', error);
Expand Down Expand Up @@ -190,7 +190,7 @@ export class WCSolanaWallet extends SolanaWallet implements IWCCommon {
const result = await this.provider.request({
method: 'solana_signMessage',
params: { message: base58.encode(message), pubkey: address }
}) as Uint8Array;
}, undefined, this.wcWallet?.options?.signingRequestExpiry) as Uint8Array;
return result;
} catch (error) {
console.log('sign message error:', error);
Expand All @@ -217,7 +217,8 @@ export class WCSolanaWallet extends SolanaWallet implements IWCCommon {
...transaction,
transaction: transaction.serialize({ verifySignatures: false }).toString('base64')
}
}
},
expiry: this.wcWallet?.options?.signingRequestExpiry,
});

const account = await this.getAccount('solana');
Expand Down
11 changes: 7 additions & 4 deletions packages/core/src/wallets/wc-wallets/wc-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { fromByteArray, toByteArray } from 'base64-js';
import { BroadcastMode } from 'interchainjs';

import { WalletConnectIcon } from '../../constant';
import { DirectSignDoc, SignType, Wallet, WalletAccount, WCDirectSignResponse, WcEventTypes, WcProviderEventType } from '../../types';
import { DirectSignDoc, SignType, Wallet, WalletAccount, WCDirectSignResponse, WcEventTypes, WcProviderEventType, WCWalletOptions } from '../../types';
import { MultiChainWallet } from '../multichain-wallet';
import { isWCCommon } from './wc-common';

Expand All @@ -35,11 +35,13 @@ export class WCWallet extends MultiChainWallet {

accountToRestore: WalletAccount | null = null;

options?: WCWalletOptions;

setAccountToRestore(account: WalletAccount) {
this.accountToRestore = account;
}

constructor(option?: Wallet, walletConnectOption?: SignClientTypes.Options) {
constructor(option?: Wallet, walletConnectOption?: SignClientTypes.Options, wcWalletOptions?: WCWalletOptions) {
const defaultWalletConnectOption: Wallet = {
name: 'WalletConnect',
prettyName: 'Wallet Connect',
Expand All @@ -50,6 +52,7 @@ export class WCWallet extends MultiChainWallet {
super({ ...defaultWalletConnectOption, ...option });

this.walletConnectOption = walletConnectOption;
this.options = wcWalletOptions;
}

async init(): Promise<void> {
Expand Down Expand Up @@ -266,7 +269,7 @@ export class WCWallet extends MultiChainWallet {
signerAddress: signer,
signDoc,
},
}, `cosmos:${chainId}`);
}, `cosmos:${chainId}`, this.options?.signingRequestExpiry);

return result as AminoSignResponse;
} catch (error) {
Expand Down Expand Up @@ -304,7 +307,7 @@ export class WCWallet extends MultiChainWallet {
const result = await (this.provider.request({
method: 'cosmos_signDirect',
params: signDocValue,
}, `cosmos:${chainId}`) as Promise<WCDirectSignResponse>);
}, `cosmos:${chainId}`, this.options?.signingRequestExpiry) as Promise<WCDirectSignResponse>);

return {
signed: {
Expand Down