@0xsequence/provider
Advanced tools
Comparing version 0.9.6 to 0.10.0
# @0xsequence/provider | ||
## 0.10.0 | ||
### Minor Changes | ||
- Deployed new contracts with ERC1271 signer support | ||
### Patch Changes | ||
- Updated dependencies [undefined] | ||
- @0xsequence/abi@0.10.0 | ||
- @0xsequence/auth@0.10.0 | ||
- @0xsequence/config@0.10.0 | ||
- @0xsequence/network@0.10.0 | ||
- @0xsequence/transactions@0.10.0 | ||
- @0xsequence/utils@0.10.0 | ||
- @0xsequence/wallet@0.10.0 | ||
## 0.9.6 | ||
@@ -4,0 +21,0 @@ |
@@ -15,8 +15,8 @@ import { BigNumberish, BytesLike } from 'ethers'; | ||
signAuthTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, message: Record<string, any>, allSigners?: boolean): Promise<string>; | ||
isValidSignature(address: string, digest: Uint8Array, signature: string, chainId: number, walletContext?: WalletContext): Promise<boolean>; | ||
isValidMessageSignature(address: string, message: string | Uint8Array, signature: string, chainId: number, walletContext?: WalletContext): Promise<boolean>; | ||
isValidTypedDataSignature(address: string, typedData: TypedData, signature: string, chainId: number, walletContext?: WalletContext): Promise<boolean>; | ||
recoverWalletConfig: (address: string, digest: BytesLike, signature: string | DecodedSignature, chainId: BigNumberish, walletContext?: WalletContext) => Promise<WalletConfig>; | ||
recoverWalletConfigFromMessage: (address: string, message: string | Uint8Array, signature: string | DecodedSignature, chainId: BigNumberish, walletContext?: WalletContext) => Promise<WalletConfig>; | ||
recoverWalletConfigFromTypedData: (address: string, typedData: TypedData, signature: string | DecodedSignature, chainId: BigNumberish, walletContext?: WalletContext) => Promise<WalletConfig>; | ||
isValidSignature(address: string, digest: Uint8Array, signature: string, chainId: number, walletContext?: WalletContext): Promise<boolean | undefined>; | ||
isValidMessageSignature(address: string, message: string | Uint8Array, signature: string, chainId: number, walletContext?: WalletContext): Promise<boolean | undefined>; | ||
isValidTypedDataSignature(address: string, typedData: TypedData, signature: string, chainId: number, walletContext?: WalletContext): Promise<boolean | undefined>; | ||
recoverWalletConfig: (address: string, digest: BytesLike, signature: string | DecodedSignature, chainId: BigNumberish, walletContext?: any) => Promise<WalletConfig>; | ||
recoverWalletConfigFromMessage: (address: string, message: string | Uint8Array, signature: string | DecodedSignature, chainId: BigNumberish, walletContext?: any) => Promise<WalletConfig>; | ||
recoverWalletConfigFromTypedData: (address: string, typedData: TypedData, signature: string | DecodedSignature, chainId: BigNumberish, walletContext?: any) => Promise<WalletConfig>; | ||
} |
import EventEmitter from 'eventemitter3'; | ||
import { ProviderTransport, ProviderMessage, ProviderMessageRequest, ProviderMessageEvent, ProviderMessageResponse, ProviderMessageResponseCallback, WalletSession, ConnectionState } from '../types'; | ||
import { NetworkConfig, WalletContext, JsonRpcRequest, JsonRpcResponseCallback } from '@0xsequence/network'; | ||
import { NetworkConfig, WalletContext } from '@0xsequence/network'; | ||
export declare const PROVIDER_CONNECT_TIMEOUT = 8000; | ||
@@ -13,5 +13,5 @@ export declare const nextMessageIdx: () => number; | ||
protected events: EventEmitter<ProviderMessageEvent, any>; | ||
protected accountPayload: string; | ||
protected networksPayload: NetworkConfig[]; | ||
protected walletContextPayload: WalletContext; | ||
protected accountPayload: string | undefined; | ||
protected networksPayload: NetworkConfig[] | undefined; | ||
protected walletContextPayload: WalletContext | undefined; | ||
protected _registered: boolean; | ||
@@ -25,3 +25,3 @@ constructor(); | ||
isConnected(): boolean; | ||
sendAsync: (request: JsonRpcRequest, callback: JsonRpcResponseCallback, chainId?: number) => Promise<void>; | ||
sendAsync: (request: any, callback: any, chainId?: number | undefined) => Promise<void>; | ||
handleMessage(message: ProviderMessage<any>): void; | ||
@@ -34,4 +34,4 @@ sendMessageRequest: (message: ProviderMessageRequest) => Promise<ProviderMessageResponse>; | ||
waitUntilLoggedIn: () => Promise<WalletSession>; | ||
protected connect: (defaultNetworkId?: string | number) => Promise<boolean>; | ||
protected connect: (defaultNetworkId?: string | number | undefined) => Promise<boolean>; | ||
protected disconnect(): void; | ||
} |
import { WalletTransport, ProviderMessage, ProviderMessageRequest, ProviderMessageResponse } from '../types'; | ||
import { WalletRequestHandler } from './wallet-request-handler'; | ||
import { NetworkConfig, WalletContext, JsonRpcRequest, JsonRpcResponseCallback } from '@0xsequence/network'; | ||
import { NetworkConfig, WalletContext } from '@0xsequence/network'; | ||
export declare abstract class BaseWalletTransport implements WalletTransport { | ||
@@ -12,3 +12,3 @@ protected walletRequestHandler: WalletRequestHandler; | ||
unregister(): void; | ||
sendAsync: (request: JsonRpcRequest, callback: JsonRpcResponseCallback, chainId?: number) => Promise<never>; | ||
sendAsync: (request: any, callback: any, chainId?: number | undefined) => Promise<never>; | ||
handleMessage: (message: ProviderMessage<any>) => Promise<void>; | ||
@@ -15,0 +15,0 @@ sendMessageRequest: (message: ProviderMessageRequest) => Promise<ProviderMessageResponse>; |
import { ProviderMessage, ProviderTransport, ProviderMessageEvent, ProviderMessageRequest, ProviderMessageResponse, WalletSession } from '../../types'; | ||
import { JsonRpcRequest, JsonRpcResponseCallback } from '@0xsequence/network'; | ||
export declare class MuxMessageProvider implements ProviderTransport { | ||
@@ -10,3 +9,3 @@ private messageProviders; | ||
unregister: () => void; | ||
openWallet: (path?: string, state?: any, defaultNetworkId?: string | number) => void; | ||
openWallet: (path?: string | undefined, state?: any, defaultNetworkId?: string | number | undefined) => void; | ||
closeWallet(): void; | ||
@@ -16,3 +15,3 @@ isConnected(): boolean; | ||
once(event: ProviderMessageEvent, fn: (...args: any[]) => void): void; | ||
sendAsync: (request: JsonRpcRequest, callback: JsonRpcResponseCallback, chainId?: number) => Promise<void>; | ||
sendAsync: (request: any, callback: any, chainId?: number | undefined) => Promise<void>; | ||
sendMessage(message: ProviderMessage<any>): void; | ||
@@ -19,0 +18,0 @@ sendMessageRequest: (message: ProviderMessageRequest) => Promise<ProviderMessageResponse>; |
@@ -9,5 +9,5 @@ import { BaseProviderTransport } from '../base-provider-transport'; | ||
unregister: () => void; | ||
openWallet: (path?: string, state?: any, defaultNetworkId?: string | number) => void; | ||
openWallet: (path?: string | undefined, state?: any, defaultNetworkId?: string | number | undefined) => void; | ||
closeWallet(): void; | ||
sendMessage(message: ProviderMessage<any>): void; | ||
} |
import { ProviderMessageRequest, ProviderMessageResponse, WalletMessageEvent, ProviderMessageRequestHandler, MessageToSign } from '../types'; | ||
import { ExternalProvider } from '@ethersproject/providers'; | ||
import { Networks, NetworkConfig, JsonRpcHandler, JsonRpcRequest, JsonRpcResponseCallback } from '@0xsequence/network'; | ||
import { Networks, NetworkConfig, JsonRpcHandler } from '@0xsequence/network'; | ||
import { Signer } from '@0xsequence/wallet'; | ||
@@ -16,3 +16,3 @@ import { TransactionRequest } from '@0xsequence/transactions'; | ||
sendMessageRequest(message: ProviderMessageRequest): Promise<ProviderMessageResponse>; | ||
sendAsync: (request: JsonRpcRequest, callback: JsonRpcResponseCallback, chainId?: number) => Promise<void>; | ||
sendAsync: (request: any, callback: any, chainId?: number | undefined) => Promise<void>; | ||
on: (event: WalletMessageEvent, fn: (...args: any[]) => void) => void; | ||
@@ -19,0 +19,0 @@ once: (event: WalletMessageEvent, fn: (...args: any[]) => void) => void; |
@@ -9,3 +9,3 @@ import { ProviderMessage } from '../../types'; | ||
unregister: () => void; | ||
openWallet: (path?: string, state?: any, defaultNetworkId?: string | number) => void; | ||
openWallet: (path?: string | undefined, state?: any, defaultNetworkId?: string | number | undefined) => void; | ||
closeWallet(): void; | ||
@@ -12,0 +12,0 @@ private onWindowEvent; |
@@ -12,9 +12,9 @@ import { NetworkConfig, WalletContext, JsonRpcRequest, JsonRpcResponse, JsonRpcHandler } from '@0xsequence/network'; | ||
export interface ProviderTransport extends JsonRpcHandler, ProviderMessageTransport, ProviderMessageRequestHandler { | ||
register(): any; | ||
unregister(): any; | ||
openWallet(path?: string, state?: any, defaultNetworkId?: string | number): any; | ||
closeWallet(): any; | ||
register(): void; | ||
unregister(): void; | ||
openWallet(path?: string, state?: any, defaultNetworkId?: string | number): void; | ||
closeWallet(): void; | ||
isConnected(): boolean; | ||
on(event: ProviderMessageEvent, fn: (...args: any[]) => void): any; | ||
once(event: ProviderMessageEvent, fn: (...args: any[]) => void): any; | ||
on(event: ProviderMessageEvent, fn: (...args: any[]) => void): void; | ||
once(event: ProviderMessageEvent, fn: (...args: any[]) => void): void; | ||
waitUntilConnected(): Promise<boolean>; | ||
@@ -24,11 +24,11 @@ waitUntilLoggedIn(): Promise<WalletSession>; | ||
export interface WalletTransport extends JsonRpcHandler, ProviderMessageTransport, ProviderMessageRequestHandler { | ||
register(): any; | ||
unregister(): any; | ||
register(): void; | ||
unregister(): void; | ||
notifyConnect(connectInfo: { | ||
chainId?: string; | ||
sessionId?: string; | ||
}): any; | ||
notifyAccountsChanged(accounts: string[]): any; | ||
notifyChainChanged(connectInfo: any): any; | ||
notifyNetworks(networks: NetworkConfig[]): any; | ||
}): void; | ||
notifyAccountsChanged(accounts: string[]): void; | ||
notifyChainChanged(connectInfo: any): void; | ||
notifyNetworks(networks: NetworkConfig[]): void; | ||
} | ||
@@ -35,0 +35,0 @@ export interface ProviderMessage<T> { |
import { BigNumberish, BytesLike } from 'ethers'; | ||
import { WalletContext } from '@0xsequence/network'; | ||
import { WalletConfig } from '@0xsequence/config'; | ||
import { Web3Provider } from './provider'; | ||
import { DecodedSignature } from '@0xsequence/wallet'; | ||
export declare const isValidSignature: (address: string, digest: Uint8Array, sig: string, provider: Web3Provider, chainId?: number, walletContext?: WalletContext) => Promise<boolean>; | ||
export declare const recoverWalletConfig: (address: string, digest: BytesLike, signature: string | DecodedSignature, chainId: BigNumberish, walletContext?: WalletContext) => WalletConfig; | ||
export declare const isValidSignature: (address: string, digest: Uint8Array, sig: string, provider: Web3Provider, chainId?: number | undefined, walletContext?: any) => Promise<boolean | undefined>; | ||
export declare const recoverWalletConfig: (address: string, digest: BytesLike, signature: string | DecodedSignature, chainId: BigNumberish, walletContext?: any) => WalletConfig; |
@@ -20,3 +20,3 @@ import { NetworkConfig, WalletContext, ChainId } from '@0xsequence/network'; | ||
closeWallet(): void; | ||
getProvider(chainId?: ChainId): Web3Provider; | ||
getProvider(chainId?: ChainId): Web3Provider | undefined; | ||
getSigner(chainId?: ChainId): Web3Signer; | ||
@@ -27,4 +27,4 @@ getWalletContext(): Promise<WalletContext>; | ||
isDeployed(chainId?: ChainId): Promise<boolean>; | ||
on(event: ProviderMessageEvent, fn: (...args: any[]) => void): any; | ||
once(event: ProviderMessageEvent, fn: (...args: any[]) => void): any; | ||
on(event: ProviderMessageEvent, fn: (...args: any[]) => void): void; | ||
once(event: ProviderMessageEvent, fn: (...args: any[]) => void): void; | ||
commands: WalletCommands; | ||
@@ -41,3 +41,3 @@ } | ||
private init; | ||
login: (refresh?: boolean) => Promise<boolean>; | ||
login: (refresh?: boolean | undefined) => Promise<boolean>; | ||
logout(): void; | ||
@@ -49,6 +49,6 @@ getProviderConfig(): ProviderConfig; | ||
getAddress: () => Promise<string>; | ||
getNetworks: (chainId?: ChainId) => Promise<NetworkConfig[]>; | ||
getNetworks: (chainId?: any) => Promise<NetworkConfig[]>; | ||
getChainId: () => Promise<number>; | ||
getAuthChainId: () => Promise<number>; | ||
openWallet: (path?: string, state?: any) => Promise<boolean>; | ||
openWallet: (path?: string | undefined, state?: any) => Promise<boolean>; | ||
closeWallet: () => void; | ||
@@ -55,0 +55,0 @@ getProvider(chainId?: ChainId): Web3Provider | undefined; |
{ | ||
"name": "@0xsequence/provider", | ||
"version": "0.9.6", | ||
"version": "0.10.0", | ||
"description": "provider sub-package for Sequence", | ||
@@ -16,9 +16,9 @@ "repository": "https://github.com/0xsequence/sequence.js/tree/master/packages/provider", | ||
"dependencies": { | ||
"@0xsequence/abi": "^0.9.6", | ||
"@0xsequence/auth": "^0.9.6", | ||
"@0xsequence/config": "^0.9.6", | ||
"@0xsequence/network": "^0.9.6", | ||
"@0xsequence/transactions": "^0.9.6", | ||
"@0xsequence/utils": "^0.9.6", | ||
"@0xsequence/wallet": "^0.9.6", | ||
"@0xsequence/abi": "^0.10.0", | ||
"@0xsequence/auth": "^0.10.0", | ||
"@0xsequence/config": "^0.10.0", | ||
"@0xsequence/network": "^0.10.0", | ||
"@0xsequence/transactions": "^0.10.0", | ||
"@0xsequence/utils": "^0.10.0", | ||
"@0xsequence/wallet": "^0.10.0", | ||
"@ethersproject/abstract-signer": "5.0.12", | ||
@@ -25,0 +25,0 @@ "@ethersproject/hash": "^5.0.11", |
@@ -52,3 +52,3 @@ import { ethers, BigNumberish, BytesLike } from 'ethers' | ||
walletContext?: WalletContext | ||
): Promise<boolean> { | ||
): Promise<boolean | undefined> { | ||
const provider = this.wallet.getProvider(chainId) | ||
@@ -66,3 +66,3 @@ if (!provider) throw new Error(`unable to get provider for chainId ${chainId}`) | ||
walletContext?: WalletContext | ||
): Promise<boolean> { | ||
): Promise<boolean | undefined> { | ||
return this.isValidSignature(address, encodeMessageDigest(message), signature, chainId, walletContext) | ||
@@ -78,3 +78,3 @@ } | ||
walletContext?: WalletContext | ||
): Promise<boolean> { | ||
): Promise<boolean | undefined> { | ||
return this.isValidSignature(address, encodeTypedDataDigest(typedData), signature, chainId, walletContext) | ||
@@ -81,0 +81,0 @@ } |
@@ -68,3 +68,3 @@ import { ethers } from 'ethers' | ||
constructor(signer: Signer, networks?: Networks) { | ||
const walletRequestHandler = new WalletRequestHandler(signer, null, networks) | ||
const walletRequestHandler = new WalletRequestHandler(signer, null, networks || []) | ||
super(walletRequestHandler) | ||
@@ -100,3 +100,3 @@ } | ||
this._index = 0 | ||
return this._address | ||
return ethers.utils.getAddress(this._address) | ||
} | ||
@@ -203,4 +203,4 @@ | ||
// https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign | ||
return await provider.send('eth_sign', [ | ||
address.toLowerCase(), ethers.utils.hexlify(data) | ||
return await provider!.send('eth_sign', [ | ||
address, ethers.utils.hexlify(data) | ||
]) | ||
@@ -218,3 +218,3 @@ } | ||
return await this.provider.send('eth_signTypedData_v4', [ | ||
(await this.getAddress()).toLowerCase(), | ||
await this.getAddress(), | ||
ethers.utils._TypedDataEncoder.getPayload(domain, types, message) | ||
@@ -229,9 +229,9 @@ ], maybeNetworkId(chainId) || this.defaultChainId) | ||
return this.sendUncheckedTransaction(transaction, chainId).then((hash) => { | ||
const tx = this.sendUncheckedTransaction(transaction, chainId).then((hash) => { | ||
return ethers.utils.poll(() => { | ||
return provider.getTransaction(hash).then((tx: TransactionResponse) => { | ||
return provider!.getTransaction(hash).then((tx: TransactionResponse) => { | ||
if (tx === null) { return undefined } | ||
return provider._wrapTransaction(tx, hash) | ||
return provider!._wrapTransaction(tx, hash) | ||
}) | ||
}, { onceBlock: this.provider }).catch((error: Error) => { | ||
}, { onceBlock: this.provider! }).catch((error: Error) => { | ||
(<any>error).transactionHash = hash | ||
@@ -241,2 +241,5 @@ throw error | ||
}) | ||
// @ts-ignore | ||
return tx | ||
} | ||
@@ -286,3 +289,3 @@ | ||
const provider = await this.getSender(this.defaultChainId) | ||
return [config, provider._wrapTransaction(tx, tx.hash)] | ||
return [config, provider!._wrapTransaction(tx, tx.hash)] | ||
} | ||
@@ -295,7 +298,7 @@ | ||
const tx = await provider.send('sequence_publishConfig', []) | ||
const tx = await provider!.send('sequence_publishConfig', []) | ||
if (tx === null) { | ||
return undefined | ||
} | ||
return provider._wrapTransaction(tx, tx.hash) | ||
return provider!._wrapTransaction(tx, tx.hash) | ||
} | ||
@@ -305,4 +308,4 @@ | ||
const provider = await this.getSender(maybeNetworkId(chainId)) | ||
const walletCode = await provider.getCode(await this.getAddress()) | ||
return walletCode && walletCode !== "0x" | ||
const walletCode = await provider!.getCode(await this.getAddress()) | ||
return !!walletCode && walletCode !== "0x" | ||
} | ||
@@ -321,6 +324,3 @@ | ||
const fromAddress = this.getAddress().then((address) => { | ||
if (address) { address = address.toLowerCase() } | ||
return address | ||
}) | ||
const fromAddress = this.getAddress() | ||
@@ -342,6 +342,6 @@ // NOTE: we do not use provider estimation, and instead rely on our relayer to determine the gasLimit and gasPrice | ||
tx: resolveProperties(transaction), | ||
sender: fromAddress | ||
sender: await fromAddress | ||
}).then(({ tx, sender }) => { | ||
if (tx.from != null) { | ||
if (tx.from.toLowerCase() !== sender) { | ||
if (ethers.utils.getAddress(tx.from) !== sender) { | ||
// logger.throwArgumentError("from address mismatch", "transaction", transaction) | ||
@@ -351,3 +351,3 @@ throw new Error(`from address mismatch for transaction ${transaction}`) | ||
} else { | ||
tx.from = sender; | ||
tx.from = sender | ||
} | ||
@@ -357,3 +357,3 @@ | ||
return provider.send('eth_sendTransaction', [hexTx]).then((hash) => { | ||
return provider!.send('eth_sendTransaction', [hexTx]).then((hash) => { | ||
return hash | ||
@@ -373,3 +373,3 @@ }, (error) => { | ||
const address = await this.getAddress() | ||
return this.provider.send("personal_unlockAccount", [address.toLowerCase(), password, null]) | ||
return this.provider.send("personal_unlockAccount", [address, password, null]) | ||
} | ||
@@ -426,3 +426,3 @@ } | ||
result['auxiliary'] = [] | ||
auxiliary.forEach(a => { | ||
auxiliary.forEach((a: any) => { | ||
result['auxiliary'].push(hexlifyTransaction(a)) | ||
@@ -429,0 +429,0 @@ }) |
@@ -11,2 +11,3 @@ import EventEmitter from 'eventemitter3' | ||
import { NetworkConfig, WalletContext, JsonRpcRequest, JsonRpcResponseCallback, JsonRpcResponse } from '@0xsequence/network' | ||
import { ethers } from 'ethers' | ||
@@ -29,5 +30,5 @@ export const PROVIDER_CONNECT_TIMEOUT = 8000 // in ms | ||
protected accountPayload: string | ||
protected networksPayload: NetworkConfig[] | ||
protected walletContextPayload: WalletContext | ||
protected accountPayload: string | undefined | ||
protected networksPayload: NetworkConfig[] | undefined | ||
protected walletContextPayload: WalletContext | undefined | ||
@@ -172,3 +173,3 @@ protected _registered: boolean | ||
if (message.data && message.data.length > 0) { | ||
this.accountPayload = message.data[0].toLowerCase() | ||
this.accountPayload = ethers.utils.getAddress(message.data[0]) | ||
this.events.emit('accountsChanged', [this.accountPayload]) | ||
@@ -213,4 +214,6 @@ } else { | ||
reject(error) | ||
} else if (response) { | ||
resolve(response) | ||
} else { | ||
resolve(response) | ||
throw new Error('no valid response to return') | ||
} | ||
@@ -276,3 +279,3 @@ } | ||
const login = Promise.all([ | ||
new Promise<string>(resolve => { | ||
new Promise<string | undefined>(resolve => { | ||
if (this.accountPayload) { | ||
@@ -316,3 +319,3 @@ resolve(this.accountPayload) | ||
const disconnect = new Promise((_, reject) => { | ||
const disconnect = new Promise<WalletSession>((_, reject) => { | ||
this.events.once('disconnect', () => { | ||
@@ -345,3 +348,3 @@ reject(new Error('user disconnected the wallet')) | ||
// Continually send connect requesst until we're connected or timeout passes | ||
let connected: boolean = undefined | ||
let connected: boolean | undefined = undefined | ||
const postMessageUntilConnected = () => { | ||
@@ -354,2 +357,3 @@ if (!this.registered) return false | ||
setTimeout(postMessageUntilConnected, 200) | ||
return | ||
} | ||
@@ -356,0 +360,0 @@ postMessageUntilConnected() |
@@ -12,3 +12,3 @@ import { BaseProviderTransport, nextMessageIdx } from '../base-provider-transport' | ||
private messageProviders: ProviderTransport[] | ||
private provider: ProviderTransport | ||
private provider: ProviderTransport | undefined | ||
@@ -15,0 +15,0 @@ constructor(...messageProviders: ProviderTransport[]) { |
@@ -23,2 +23,3 @@ import { BaseWalletTransport } from '../base-wallet-transport' | ||
unregister() { | ||
// @ts-ignore | ||
this.port.handleMessage = undefined | ||
@@ -25,0 +26,0 @@ this._registered = false |
@@ -43,2 +43,3 @@ import { BaseProviderTransport, nextMessageIdx } from '../base-provider-transport' | ||
this.events.removeAllListeners() | ||
// @ts-ignore | ||
this.port.handleMessage = undefined | ||
@@ -45,0 +46,0 @@ } |
@@ -20,4 +20,4 @@ import EventEmitter from 'eventemitter3' | ||
export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, ProviderMessageRequestHandler { | ||
private signer: Signer | ||
private prompter: WalletUserPrompter | ||
private signer: Signer | null | ||
private prompter: WalletUserPrompter | null | ||
private mainnetNetworks: NetworkConfig[] | ||
@@ -57,3 +57,3 @@ private testnetNetworks: NetworkConfig[] | ||
this.notifyLogin(await this.signer.getAddress()) | ||
this.notifyLogin(await this.signer!.getAddress()) | ||
} | ||
@@ -69,3 +69,3 @@ | ||
...message, | ||
data: response | ||
data: response! | ||
} | ||
@@ -86,3 +86,3 @@ | ||
jsonrpc: '2.0', | ||
id: request.id, | ||
id: request.id!, | ||
result: null, | ||
@@ -123,3 +123,3 @@ error: null | ||
const walletAddress = await signer.getAddress() | ||
response.result = [walletAddress.toLowerCase()] | ||
response.result = [walletAddress] | ||
break | ||
@@ -129,3 +129,3 @@ } | ||
case 'eth_getBalance': { | ||
const [accountAddress, blockTag] = request.params | ||
const [accountAddress, blockTag] = request.params! | ||
const walletBalance = await provider.getBalance(accountAddress, blockTag) | ||
@@ -138,3 +138,3 @@ response.result = walletBalance.toHexString() | ||
// note: message from json-rpc input is in hex format | ||
const [signingAddress, message] = request.params | ||
const [signingAddress, message] = request.params! | ||
@@ -165,5 +165,5 @@ let sig = '' | ||
// should be an object, but in some instances may be double string encoded | ||
const [signingAddress, typedDataObject] = request.params | ||
const [signingAddress, typedDataObject] = request.params! | ||
let typedData: TypedData | ||
let typedData: TypedData | undefined = undefined | ||
if (typeof(typedDataObject) === 'string') { | ||
@@ -201,3 +201,3 @@ try { | ||
// https://eth.wiki/json-rpc/API#eth_sendtransaction | ||
const [transactionParams] = request.params | ||
const [transactionParams] = request.params! | ||
@@ -225,3 +225,3 @@ let txnHash = '' | ||
// https://eth.wiki/json-rpc/API#eth_signTransaction | ||
const [transaction] = request.params | ||
const [transaction] = request.params! | ||
const sender = ethers.utils.getAddress(transaction.from) | ||
@@ -252,8 +252,8 @@ | ||
// https://eth.wiki/json-rpc/API#eth_sendRawTransaction | ||
if (isSignedTransactions(request.params[0])) { | ||
const txChainId = BigNumber.from(request.params[0].chainId).toNumber() | ||
const tx = await (await signer.getRelayer(txChainId)).relay(request.params[0]) | ||
if (isSignedTransactions(request.params![0])) { | ||
const txChainId = BigNumber.from(request.params![0].chainId).toNumber() | ||
const tx = await (await signer.getRelayer(txChainId))!.relay(request.params![0]) | ||
response.result = (await tx).hash | ||
} else { | ||
const tx = await provider.sendTransaction(request.params[0]) | ||
const tx = await provider.sendTransaction(request.params![0]) | ||
response.result = tx.hash | ||
@@ -265,8 +265,8 @@ } | ||
case 'eth_getTransactionCount': { | ||
const address = (request.params[0] as string).toLowerCase() | ||
const tag = request.params[1] | ||
const address = ethers.utils.getAddress((request.params![0] as string)) | ||
const tag = request.params![1] | ||
const walletAddress = await signer.getAddress() | ||
const walletAddress = ethers.utils.getAddress(await signer.getAddress()) | ||
if (address === walletAddress.toLowerCase()) { | ||
if (address === walletAddress) { | ||
const count = await signer.getTransactionCount(tag) | ||
@@ -287,3 +287,3 @@ response.result = ethers.BigNumber.from(count).toHexString() | ||
case 'eth_getBlockByNumber': { | ||
response.result = await provider.getBlock(request.params[0] /* , jsonRpcRequest.params[1] */) | ||
response.result = await provider.getBlock(request.params![0] /* , jsonRpcRequest.params[1] */) | ||
break | ||
@@ -293,3 +293,3 @@ } | ||
case 'eth_getBlockByHash': { | ||
response.result = await provider.getBlock(request.params[0] /* , jsonRpcRequest.params[1] */) | ||
response.result = await provider.getBlock(request.params![0] /* , jsonRpcRequest.params[1] */) | ||
break | ||
@@ -299,3 +299,3 @@ } | ||
case 'eth_getTransactionByHash': { | ||
response.result = await provider.getTransaction(request.params[0]) | ||
response.result = await provider.getTransaction(request.params![0]) | ||
break | ||
@@ -305,3 +305,3 @@ } | ||
case 'eth_call': { | ||
const [transactionObject, blockTag] = request.params | ||
const [transactionObject, blockTag] = request.params! | ||
response.result = await provider.call(transactionObject, blockTag) | ||
@@ -312,3 +312,3 @@ break | ||
case 'eth_getCode': { | ||
const [contractAddress, blockTag] = request.params | ||
const [contractAddress, blockTag] = request.params! | ||
response.result = await provider.getCode(contractAddress, blockTag) | ||
@@ -319,3 +319,3 @@ break | ||
case 'eth_estimateGas': { | ||
const [transactionObject] = request.params | ||
const [transactionObject] = request.params! | ||
response.result = await provider.estimateGas(transactionObject) | ||
@@ -402,3 +402,3 @@ break | ||
case 'sequence_setDefaultNetwork': { | ||
const [defaultNetworkId] = request.params | ||
const [defaultNetworkId] = request.params! | ||
@@ -419,3 +419,3 @@ if (!defaultNetworkId) { | ||
// NOTE: provider here will be chain-bound if chainId is provided | ||
const providerResponse = await provider.send(request.method, request.params) | ||
const providerResponse = await provider.send(request.method, request.params!) | ||
response.result = providerResponse | ||
@@ -465,3 +465,3 @@ } | ||
async setDefaultNetwork(chainId: string | number, notifyNetworks: boolean = true): Promise<boolean> { | ||
if (!chainId) return | ||
if (!chainId) return false | ||
this._defaultNetworkId = chainId | ||
@@ -468,0 +468,0 @@ |
@@ -25,3 +25,3 @@ import { ProviderMessageRequest, ProviderMessage, ProviderMessageType, ProviderMessageResponse } from '../../types' | ||
const location = new URL(window.location.href) | ||
this._sessionId = sanitizeNumberString(location.searchParams.get('sid')) | ||
this._sessionId = sanitizeNumberString(location.searchParams.get('sid')!) | ||
location.searchParams.delete('sid') | ||
@@ -28,0 +28,0 @@ window.history.replaceState({}, document.title, location.pathname) |
@@ -5,3 +5,3 @@ import { ProviderMessage } from '../../types' | ||
// .. | ||
let registeredWindowMessageProvider: WindowMessageProvider | ||
let registeredWindowMessageProvider: WindowMessageProvider | undefined | ||
@@ -30,2 +30,3 @@ export class WindowMessageProvider extends BaseProviderTransport { | ||
this.walletWindow.close() | ||
// @ts-ignore | ||
this.walletWindow = undefined | ||
@@ -104,2 +105,3 @@ } | ||
// Popup window is available | ||
// @ts-ignore | ||
this.walletWindow = popup | ||
@@ -106,0 +108,0 @@ |
@@ -22,9 +22,9 @@ import { NetworkConfig, WalletContext, JsonRpcRequest, JsonRpcResponse, JsonRpcHandler } from '@0xsequence/network' | ||
export interface ProviderTransport extends JsonRpcHandler, ProviderMessageTransport, ProviderMessageRequestHandler { | ||
register() | ||
unregister() | ||
openWallet(path?: string, state?: any, defaultNetworkId?: string | number) | ||
closeWallet() | ||
register(): void | ||
unregister(): void | ||
openWallet(path?: string, state?: any, defaultNetworkId?: string | number): void | ||
closeWallet(): void | ||
isConnected(): boolean | ||
on(event: ProviderMessageEvent, fn: (...args: any[]) => void) | ||
once(event: ProviderMessageEvent, fn: (...args: any[]) => void) | ||
on(event: ProviderMessageEvent, fn: (...args: any[]) => void): void | ||
once(event: ProviderMessageEvent, fn: (...args: any[]) => void): void | ||
waitUntilConnected(): Promise<boolean> | ||
@@ -35,8 +35,8 @@ waitUntilLoggedIn(): Promise<WalletSession> | ||
export interface WalletTransport extends JsonRpcHandler, ProviderMessageTransport, ProviderMessageRequestHandler { | ||
register() | ||
unregister() | ||
notifyConnect(connectInfo: { chainId?: string, sessionId?: string }) | ||
notifyAccountsChanged(accounts: string[]) | ||
notifyChainChanged(connectInfo: any) | ||
notifyNetworks(networks: NetworkConfig[]) | ||
register(): void | ||
unregister(): void | ||
notifyConnect(connectInfo: { chainId?: string, sessionId?: string }): void | ||
notifyAccountsChanged(accounts: string[]): void | ||
notifyChainChanged(connectInfo: any): void | ||
notifyNetworks(networks: NetworkConfig[]): void | ||
} | ||
@@ -43,0 +43,0 @@ |
@@ -14,3 +14,3 @@ import { BigNumberish, BytesLike } from 'ethers' | ||
walletContext?: WalletContext | ||
): Promise<boolean> => { | ||
): Promise<boolean | undefined> => { | ||
chainId = chainId || await provider.getChainId() | ||
@@ -17,0 +17,0 @@ walletContext = walletContext || await provider.getSigner().getWalletContext() |
@@ -12,2 +12,3 @@ import { Networks, NetworkConfig, WalletContext, sequenceContext, ChainId, getNetworkId, JsonRpcSender, | ||
import { WalletCommands } from './commands' | ||
import { ethers } from 'ethers' | ||
@@ -31,3 +32,3 @@ export interface WalletProvider { | ||
getProvider(chainId?: ChainId): Web3Provider | ||
getProvider(chainId?: ChainId): Web3Provider | undefined | ||
getSigner(chainId?: ChainId): Web3Signer | ||
@@ -40,4 +41,4 @@ | ||
on(event: ProviderMessageEvent, fn: (...args: any[]) => void) | ||
once(event: ProviderMessageEvent, fn: (...args: any[]) => void) | ||
on(event: ProviderMessageEvent, fn: (...args: any[]) => void): void | ||
once(event: ProviderMessageEvent, fn: (...args: any[]) => void): void | ||
@@ -109,3 +110,3 @@ commands: WalletCommands | ||
if (this.config.transports?.proxyTransport?.enabled) { | ||
this.transport.proxyMessageProvider = new ProxyMessageProvider(this.config.transports.proxyTransport.appPort) | ||
this.transport.proxyMessageProvider = new ProxyMessageProvider(this.config.transports.proxyTransport.appPort!) | ||
this.transport.messageProvider.add(this.transport.proxyMessageProvider) | ||
@@ -139,3 +140,3 @@ } | ||
if (!this.session) this.session = { providerCache: {} } | ||
this.session.providerCache = this.transport.cachedProvider.getCache() | ||
this.session.providerCache = this.transport.cachedProvider!.getCache() | ||
this.saveSession(this.session) | ||
@@ -191,3 +192,3 @@ }) | ||
await this.openWallet('', { login: true }) | ||
const sessionPayload = await this.transport.messageProvider.waitUntilLoggedIn() | ||
const sessionPayload = await this.transport.messageProvider!.waitUntilLoggedIn() | ||
this.useSession(sessionPayload, true) | ||
@@ -210,3 +211,3 @@ | ||
isConnected(): boolean { | ||
return this.transport.messageProvider.isConnected() | ||
return this.transport.messageProvider!.isConnected() | ||
} | ||
@@ -218,3 +219,3 @@ | ||
this.networks !== undefined && this.networks.length > 0 && | ||
this.session.accountAddress.startsWith('0x') | ||
this.session.accountAddress!.startsWith('0x') | ||
} | ||
@@ -234,3 +235,3 @@ | ||
const session = this.getSession() | ||
return session.accountAddress | ||
return session!.accountAddress! | ||
} | ||
@@ -286,4 +287,4 @@ | ||
this.transport.messageProvider.openWallet(path, state, this.config.defaultNetworkId) | ||
await this.transport.messageProvider.waitUntilConnected() | ||
this.transport.messageProvider!.openWallet(path, state, this.config.defaultNetworkId) | ||
await this.transport.messageProvider!.waitUntilConnected() | ||
@@ -294,3 +295,3 @@ return true | ||
closeWallet = (): void => { | ||
this.transport.messageProvider.closeWallet() | ||
this.transport.messageProvider!.closeWallet() | ||
} | ||
@@ -309,5 +310,8 @@ | ||
let network = this.networks[0] | ||
let network: NetworkConfig | undefined = this.networks[0] | ||
if (chainId) { | ||
network = findNetworkConfig(this.networks, chainId) | ||
if (!network) { | ||
throw new Error(`network ${chainId} is not in the network list`) | ||
} | ||
} | ||
@@ -331,5 +335,5 @@ | ||
exceptionProviderMiddleware, | ||
new EagerProvider({ accountAddress: this.session.accountAddress, walletContext: this.session.walletContext }), | ||
new SigningProvider(this.transport.provider), | ||
this.transport.cachedProvider, | ||
new EagerProvider({ accountAddress: this.session!.accountAddress, walletContext: this.session!.walletContext }), | ||
new SigningProvider(this.transport!.provider!), | ||
this.transport.cachedProvider!, | ||
], new JsonRpcSender(rpcProvider)) | ||
@@ -345,4 +349,4 @@ | ||
exceptionProviderMiddleware, | ||
new EagerProvider({ accountAddress: this.session.accountAddress, walletContext: this.session.walletContext, chainId: network.chainId }), | ||
new SigningProvider(this.transport.provider), | ||
new EagerProvider({ accountAddress: this.session!.accountAddress, walletContext: this.session!.walletContext, chainId: network.chainId }), | ||
new SigningProvider(this.transport.provider!), | ||
new CachedProvider(network.chainId), | ||
@@ -359,7 +363,7 @@ ], new JsonRpcSender(rpcProvider)) | ||
async getAuthProvider(): Promise<Web3Provider> { | ||
return this.getProvider((await this.getAuthNetwork()).chainId) | ||
return this.getProvider((await this.getAuthNetwork()).chainId)! | ||
} | ||
async getAuthNetwork(): Promise<NetworkConfig> { | ||
return (await this.getNetworks()).find((n) => n.isAuthChain) | ||
return (await this.getNetworks()).find((n) => n.isAuthChain)! | ||
} | ||
@@ -372,3 +376,3 @@ | ||
getSigner(chainId?: ChainId): Web3Signer { | ||
return this.getProvider(chainId).getSigner() | ||
return this.getProvider(chainId)!.getSigner() | ||
} | ||
@@ -397,13 +401,13 @@ | ||
on(event: ProviderMessageEvent, fn: (...args: any[]) => void) { | ||
this.transport.messageProvider.on(event, fn) | ||
this.transport.messageProvider!.on(event, fn) | ||
} | ||
once(event: ProviderMessageEvent, fn: (...args: any[]) => void) { | ||
this.transport.messageProvider.once(event, fn) | ||
this.transport.messageProvider!.once(event, fn) | ||
} | ||
private loadSession = (): WalletSession => { | ||
private loadSession = (): WalletSession | undefined => { | ||
const data = window.localStorage.getItem('@sequence.session') | ||
if (!data || data === '') { | ||
return null | ||
return undefined | ||
} | ||
@@ -446,3 +450,3 @@ try { | ||
if (session.providerCache) { | ||
this.transport.cachedProvider.setCache(session.providerCache) | ||
this.transport.cachedProvider!.setCache(session.providerCache) | ||
} | ||
@@ -458,3 +462,3 @@ | ||
if (!this.session) this.session = {} | ||
this.session.accountAddress = accountAddress.toLowerCase() | ||
this.session.accountAddress = ethers.utils.getAddress(accountAddress) | ||
} | ||
@@ -491,3 +495,3 @@ | ||
this.config.networks.forEach(n => { | ||
const network = findNetworkConfig(this.networks, n.chainId || n.name) | ||
const network = findNetworkConfig(this.networks, n.chainId || n.name!) | ||
if (!network) return | ||
@@ -508,3 +512,3 @@ updateNetworkConfig(n, network) | ||
this.session = undefined | ||
this.networks = undefined | ||
this.networks = [] | ||
this.providers = {} | ||
@@ -511,0 +515,0 @@ this.transport.cachedProvider?.clearCache() |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
369100
9039
+ Added@0xsequence/abi@0.10.9(transitive)
+ Added@0xsequence/api@0.10.9(transitive)
+ Added@0xsequence/auth@0.10.9(transitive)
+ Added@0xsequence/chaind@0.10.9(transitive)
+ Added@0xsequence/config@0.10.9(transitive)
+ Added@0xsequence/guard@0.10.9(transitive)
+ Added@0xsequence/network@0.10.9(transitive)
+ Added@0xsequence/relayer@0.10.9(transitive)
+ Added@0xsequence/transactions@0.10.9(transitive)
+ Added@0xsequence/utils@0.10.9(transitive)
+ Added@0xsequence/wallet@0.10.9(transitive)
+ Added@ethersproject/abstract-signer@5.0.14(transitive)
- Removed@0xsequence/abi@0.9.6(transitive)
- Removed@0xsequence/api@0.9.6(transitive)
- Removed@0xsequence/auth@0.9.6(transitive)
- Removed@0xsequence/chaind@0.9.6(transitive)
- Removed@0xsequence/config@0.9.6(transitive)
- Removed@0xsequence/guard@0.9.6(transitive)
- Removed@0xsequence/network@0.9.6(transitive)
- Removed@0xsequence/relayer@0.9.6(transitive)
- Removed@0xsequence/transactions@0.9.6(transitive)
- Removed@0xsequence/utils@0.9.6(transitive)
- Removed@0xsequence/wallet@0.9.6(transitive)
Updated@0xsequence/abi@^0.10.0
Updated@0xsequence/auth@^0.10.0
Updated@0xsequence/config@^0.10.0
Updated@0xsequence/network@^0.10.0
Updated@0xsequence/utils@^0.10.0
Updated@0xsequence/wallet@^0.10.0