@0xsequence/provider 0.0.0-20230505164841 → 0.0.0-20230509145455
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/0xsequence-provider.cjs.d.ts +11 -1
- package/dist/0xsequence-provider.cjs.js +15 -6
- package/package.json +10 -11
- package/src/provider.ts +71 -77
- package/src/transports/base-provider-transport.ts +2 -3
- package/src/transports/base-wallet-transport.ts +10 -9
- package/src/transports/wallet-request-handler.ts +168 -221
- package/src/types.ts +15 -10
- package/src/utils/index.ts +51 -46
- package/src/utils.ts +98 -62
- package/src/wallet.ts +51 -33
- package/dist/0xsequence-provider.cjs.dev.js +0 -3874
- package/dist/0xsequence-provider.cjs.prod.js +0 -3874
- package/dist/0xsequence-provider.esm.js +0 -3829
- package/dist/declarations/src/eip191exceptions.d.ts +0 -3
- package/dist/declarations/src/extended.d.ts +0 -6
- package/dist/declarations/src/index.d.ts +0 -5
- package/dist/declarations/src/provider.d.ts +0 -68
- package/dist/declarations/src/transports/base-provider-transport.d.ts +0 -44
- package/dist/declarations/src/transports/base-wallet-transport.d.ts +0 -39
- package/dist/declarations/src/transports/extension-transport/base-injected-transport.d.ts +0 -17
- package/dist/declarations/src/transports/extension-transport/extension-message-handler.d.ts +0 -12
- package/dist/declarations/src/transports/extension-transport/extension-message-provider.d.ts +0 -11
- package/dist/declarations/src/transports/extension-transport/index.d.ts +0 -3
- package/dist/declarations/src/transports/index.d.ts +0 -8
- package/dist/declarations/src/transports/mux-transport/index.d.ts +0 -1
- package/dist/declarations/src/transports/mux-transport/mux-message-provider.d.ts +0 -23
- package/dist/declarations/src/transports/proxy-transport/index.d.ts +0 -3
- package/dist/declarations/src/transports/proxy-transport/proxy-message-channel.d.ts +0 -15
- package/dist/declarations/src/transports/proxy-transport/proxy-message-handler.d.ts +0 -12
- package/dist/declarations/src/transports/proxy-transport/proxy-message-provider.d.ts +0 -12
- package/dist/declarations/src/transports/unreal-transport/index.d.ts +0 -2
- package/dist/declarations/src/transports/unreal-transport/overridelogs.d.ts +0 -4
- package/dist/declarations/src/transports/unreal-transport/unreal-message-handler.d.ts +0 -14
- package/dist/declarations/src/transports/unreal-transport/unreal-message-provider.d.ts +0 -15
- package/dist/declarations/src/transports/wallet-request-handler.d.ts +0 -62
- package/dist/declarations/src/transports/window-transport/index.d.ts +0 -2
- package/dist/declarations/src/transports/window-transport/window-message-handler.d.ts +0 -15
- package/dist/declarations/src/transports/window-transport/window-message-provider.d.ts +0 -13
- package/dist/declarations/src/types.d.ts +0 -236
- package/dist/declarations/src/utils/index.d.ts +0 -15
- package/dist/declarations/src/utils.d.ts +0 -32
- package/dist/declarations/src/wallet.d.ts +0 -105
- package/src/extended.ts +0 -23
|
@@ -1 +1,11 @@
|
|
|
1
|
-
export
|
|
1
|
+
// are you seeing an error that a default export doesn't exist but your source file has a default export?
|
|
2
|
+
// you should run `yarn` or `yarn preconstruct dev` if preconstruct dev isn't in your postinstall hook
|
|
3
|
+
|
|
4
|
+
// curious why you need to?
|
|
5
|
+
// this file exists so that you can import from the entrypoint normally
|
|
6
|
+
// except that it points to your source file and you don't need to run build constantly
|
|
7
|
+
// which means we need to re-export all of the modules from your source file
|
|
8
|
+
// and since export * doesn't include default exports, we need to read your source file
|
|
9
|
+
// to check for a default export and re-export it if it exists
|
|
10
|
+
// it's not ideal, but it works pretty well ¯\_(ツ)_/¯
|
|
11
|
+
export * from "../src/index";
|
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
// this file might look strange and you might be wondering what it's for
|
|
3
|
+
// it's lets you import your source files by importing this entrypoint
|
|
4
|
+
// as you would import it if it was built with preconstruct build
|
|
5
|
+
// this file is slightly different to some others though
|
|
6
|
+
// it has a require hook which compiles your code with Babel
|
|
7
|
+
// this means that you don't have to set up @babel/register or anything like that
|
|
8
|
+
// but you can still require this module and it'll be compiled
|
|
2
9
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
10
|
+
// this bit of code imports the require hook and registers it
|
|
11
|
+
let unregister = require("../../../node_modules/.pnpm/@preconstruct+hook@0.4.0/node_modules/@preconstruct/hook").___internalHook(typeof __dirname === 'undefined' ? undefined : __dirname, "../../..", "..");
|
|
12
|
+
|
|
13
|
+
// this re-exports the source file
|
|
14
|
+
module.exports = require("../src/index.ts");
|
|
15
|
+
|
|
16
|
+
unregister();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xsequence/provider",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-20230509145455",
|
|
4
4
|
"description": "provider sub-package for Sequence",
|
|
5
5
|
"repository": "https://github.com/0xsequence/sequence.js/tree/master/packages/provider",
|
|
6
6
|
"source": "src/index.ts",
|
|
@@ -9,17 +9,16 @@
|
|
|
9
9
|
"author": "Horizon Blockchain Games",
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"dependencies": {
|
|
12
|
+
"@0xsequence/abi": "0.0.0-20230509145455",
|
|
13
|
+
"@0xsequence/auth": "0.0.0-20230509145455",
|
|
14
|
+
"@0xsequence/config": "0.0.0-20230509145455",
|
|
15
|
+
"@0xsequence/network": "0.0.0-20230509145455",
|
|
16
|
+
"@0xsequence/relayer": "0.0.0-20230509145455",
|
|
17
|
+
"@0xsequence/transactions": "0.0.0-20230509145455",
|
|
18
|
+
"@0xsequence/utils": "0.0.0-20230509145455",
|
|
19
|
+
"@0xsequence/wallet": "0.0.0-20230509145455",
|
|
12
20
|
"eventemitter2": "^6.4.5",
|
|
13
|
-
"webextension-polyfill": "^0.10.0"
|
|
14
|
-
"@0xsequence/abi": "0.0.0-20230505164841",
|
|
15
|
-
"@0xsequence/account": "0.0.0-20230505164841",
|
|
16
|
-
"@0xsequence/auth": "0.0.0-20230505164841",
|
|
17
|
-
"@0xsequence/core": "0.0.0-20230505164841",
|
|
18
|
-
"@0xsequence/migration": "0.0.0-20230505164841",
|
|
19
|
-
"@0xsequence/network": "0.0.0-20230505164841",
|
|
20
|
-
"@0xsequence/relayer": "0.0.0-20230505164841",
|
|
21
|
-
"@0xsequence/utils": "0.0.0-20230505164841",
|
|
22
|
-
"@0xsequence/wallet": "0.0.0-20230505164841"
|
|
21
|
+
"webextension-polyfill": "^0.10.0"
|
|
23
22
|
},
|
|
24
23
|
"peerDependencies": {
|
|
25
24
|
"ethers": ">=5.5 < 6"
|
package/src/provider.ts
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
|
-
import { ethers, BytesLike, Bytes, providers, TypedDataDomain, TypedDataField } from 'ethers'
|
|
2
|
-
|
|
1
|
+
import { ethers, BytesLike, Bytes, providers, TypedDataDomain, TypedDataField, BigNumber } from 'ethers'
|
|
3
2
|
import {
|
|
4
3
|
NetworkConfig,
|
|
4
|
+
WalletContext,
|
|
5
5
|
ChainIdLike,
|
|
6
6
|
JsonRpcHandler,
|
|
7
7
|
JsonRpcFetchFunc,
|
|
8
8
|
JsonRpcRequest,
|
|
9
9
|
JsonRpcResponseCallback,
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
maybeChainId,
|
|
11
|
+
JsonRpcSender
|
|
12
12
|
} from '@0xsequence/network'
|
|
13
|
-
|
|
14
13
|
import { resolveArrayProperties, Signer } from '@0xsequence/wallet'
|
|
14
|
+
import { WalletConfig, WalletState } from '@0xsequence/config'
|
|
15
15
|
import { Relayer } from '@0xsequence/relayer'
|
|
16
16
|
import { Deferrable, shallowCopy, resolveProperties, Forbid } from '@0xsequence/utils'
|
|
17
|
+
import { TransactionRequest, TransactionResponse, SignedTransactions } from '@0xsequence/transactions'
|
|
17
18
|
import { WalletRequestHandler } from './transports/wallet-request-handler'
|
|
18
|
-
import { commons, universal } from '@0xsequence/core'
|
|
19
|
-
import { Account, AccountStatus } from '@0xsequence/account'
|
|
20
|
-
import { ExtendedTransactionRequest, toExtended } from './extended'
|
|
21
19
|
|
|
22
20
|
export class Web3Provider extends providers.Web3Provider implements JsonRpcHandler {
|
|
23
21
|
static isSequenceProvider(cand: any): cand is Web3Provider {
|
|
@@ -64,21 +62,15 @@ export class Web3Provider extends providers.Web3Provider implements JsonRpcHandl
|
|
|
64
62
|
}
|
|
65
63
|
|
|
66
64
|
async getChainId(): Promise<number> {
|
|
67
|
-
//
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (this._defaultChainId) {
|
|
71
|
-
const networks = await this.getNetworks()
|
|
72
|
-
if (networks.find((n) => n.chainId === this._defaultChainId)) return this._defaultChainId
|
|
73
|
-
throw new Error(`Default chainId ${this._defaultChainId} not supported by wallet`)
|
|
74
|
-
}
|
|
65
|
+
// TODO: is it safe to memoize this?
|
|
66
|
+
const result = await this.send('eth_chainId', [])
|
|
67
|
+
const chainId = ethers.BigNumber.from(result).toNumber()
|
|
75
68
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
69
|
+
if (this._defaultChainId && this._defaultChainId !== chainId) {
|
|
70
|
+
throw new Error(`provider chainId (${chainId}) does not match provider-bound chainId ${this._defaultChainId}`)
|
|
71
|
+
}
|
|
79
72
|
|
|
80
|
-
|
|
81
|
-
return this.send('sequence_getNetworks', [])
|
|
73
|
+
return chainId
|
|
82
74
|
}
|
|
83
75
|
}
|
|
84
76
|
|
|
@@ -88,8 +80,8 @@ export function isSequenceProvider(provider: any): provider is Web3Provider {
|
|
|
88
80
|
}
|
|
89
81
|
|
|
90
82
|
export class LocalWeb3Provider extends Web3Provider {
|
|
91
|
-
constructor(
|
|
92
|
-
const walletRequestHandler = new WalletRequestHandler(
|
|
83
|
+
constructor(signer: Signer, networks?: NetworkConfig[]) {
|
|
84
|
+
const walletRequestHandler = new WalletRequestHandler(signer, null, null, networks || [])
|
|
93
85
|
super(walletRequestHandler)
|
|
94
86
|
}
|
|
95
87
|
}
|
|
@@ -116,7 +108,7 @@ export class Web3Signer extends Signer implements TypedDataSigner {
|
|
|
116
108
|
// memoized
|
|
117
109
|
_address: string
|
|
118
110
|
_index: number
|
|
119
|
-
_context:
|
|
111
|
+
_context: WalletContext
|
|
120
112
|
_networks: NetworkConfig[]
|
|
121
113
|
private _providers: { [key: number]: Web3Provider } = {}
|
|
122
114
|
|
|
@@ -132,7 +124,7 @@ export class Web3Signer extends Signer implements TypedDataSigner {
|
|
|
132
124
|
return ethers.utils.getAddress(this._address)
|
|
133
125
|
}
|
|
134
126
|
|
|
135
|
-
signTransaction(transaction: Deferrable<
|
|
127
|
+
signTransaction(transaction: Deferrable<TransactionRequest>): Promise<string> {
|
|
136
128
|
// TODO .. since ethers isn't using this method, perhaps we will?
|
|
137
129
|
throw new Error('signTransaction is unsupported, use signTransactions instead')
|
|
138
130
|
}
|
|
@@ -183,53 +175,55 @@ export class Web3Signer extends Signer implements TypedDataSigner {
|
|
|
183
175
|
throw new Error('TODO')
|
|
184
176
|
}
|
|
185
177
|
|
|
186
|
-
async getWalletContext(): Promise<
|
|
178
|
+
async getWalletContext(): Promise<WalletContext> {
|
|
187
179
|
if (!this._context) {
|
|
188
180
|
this._context = await this.provider.send('sequence_getWalletContext', [])
|
|
189
181
|
}
|
|
190
182
|
return this._context
|
|
191
183
|
}
|
|
192
184
|
|
|
193
|
-
async getWalletConfig(chainId?: ChainIdLike): Promise<
|
|
194
|
-
|
|
195
|
-
if (!reqChainId) throw new Error('chainId is required')
|
|
196
|
-
return (await this.provider.send(
|
|
185
|
+
async getWalletConfig(chainId?: ChainIdLike): Promise<WalletConfig[]> {
|
|
186
|
+
return await this.provider.send(
|
|
197
187
|
'sequence_getWalletConfig',
|
|
198
|
-
[
|
|
199
|
-
|
|
200
|
-
)
|
|
188
|
+
[maybeChainId(chainId)],
|
|
189
|
+
maybeChainId(chainId) || this.defaultChainId
|
|
190
|
+
)
|
|
201
191
|
}
|
|
202
192
|
|
|
203
|
-
async getWalletState(chainId?: ChainIdLike): Promise<
|
|
204
|
-
|
|
205
|
-
if (!reqChainId) throw new Error('chainId is required')
|
|
206
|
-
return (await this.provider.send(
|
|
193
|
+
async getWalletState(chainId?: ChainIdLike): Promise<WalletState[]> {
|
|
194
|
+
return await this.provider.send(
|
|
207
195
|
'sequence_getWalletState',
|
|
208
|
-
[
|
|
209
|
-
|
|
210
|
-
)
|
|
196
|
+
[maybeChainId(chainId)],
|
|
197
|
+
maybeChainId(chainId) || this.defaultChainId
|
|
198
|
+
)
|
|
211
199
|
}
|
|
212
200
|
|
|
213
201
|
async getNetworks(): Promise<NetworkConfig[]> {
|
|
214
|
-
if (!this._networks)
|
|
202
|
+
if (!this._networks) {
|
|
203
|
+
this._networks = await this.provider.send('sequence_getNetworks', [])
|
|
204
|
+
}
|
|
215
205
|
return this._networks
|
|
216
206
|
}
|
|
217
207
|
|
|
218
208
|
async getSigners(): Promise<string[]> {
|
|
219
209
|
const networks = await this.getNetworks()
|
|
220
210
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
211
|
+
const authChainId = networks.find(n => n.isAuthChain)
|
|
212
|
+
if (!authChainId) {
|
|
213
|
+
throw new Error('authChainId could not be determined from network list')
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const walletConfig = await this.getWalletConfig(authChainId)
|
|
217
|
+
if (!walletConfig || walletConfig.length === 0) {
|
|
224
218
|
throw new Error(`walletConfig returned zero results for authChainId {authChainId}`)
|
|
225
219
|
}
|
|
226
220
|
|
|
227
|
-
return
|
|
221
|
+
return walletConfig[0].signers.map(s => s.address)
|
|
228
222
|
}
|
|
229
223
|
|
|
230
224
|
// signMessage matches implementation from ethers JsonRpcSigner for compatibility, but with
|
|
231
225
|
// multi-chain support.
|
|
232
|
-
async signMessage(message: BytesLike, chainId?: ChainIdLike, allSigners?: boolean
|
|
226
|
+
async signMessage(message: BytesLike, chainId?: ChainIdLike, allSigners?: boolean): Promise<string> {
|
|
233
227
|
const provider = await this.getSender(maybeChainId(chainId) || this.defaultChainId)
|
|
234
228
|
|
|
235
229
|
const data = typeof message === 'string' ? ethers.utils.toUtf8Bytes(message) : message
|
|
@@ -238,10 +232,7 @@ export class Web3Signer extends Signer implements TypedDataSigner {
|
|
|
238
232
|
// NOTE: as of ethers v5.5, it switched to using personal_sign, see
|
|
239
233
|
// https://github.com/ethers-io/ethers.js/pull/1542 and see
|
|
240
234
|
// https://github.com/WalletConnect/walletconnect-docs/issues/32 for additional info.
|
|
241
|
-
return provider!.send(
|
|
242
|
-
sequenceVerified ? 'sequence_sign' : 'personal_sign',
|
|
243
|
-
[ethers.utils.hexlify(data), address]
|
|
244
|
-
)
|
|
235
|
+
return await provider!.send('personal_sign', [ethers.utils.hexlify(data), address])
|
|
245
236
|
}
|
|
246
237
|
|
|
247
238
|
// signTypedData matches implementation from ethers JsonRpcSigner for compatibility, but with
|
|
@@ -251,16 +242,15 @@ export class Web3Signer extends Signer implements TypedDataSigner {
|
|
|
251
242
|
types: Record<string, Array<TypedDataField>>,
|
|
252
243
|
message: Record<string, any>,
|
|
253
244
|
chainId?: ChainIdLike,
|
|
254
|
-
allSigners?: boolean
|
|
255
|
-
sequenceVerified?: boolean
|
|
245
|
+
allSigners?: boolean
|
|
256
246
|
): Promise<string> {
|
|
257
247
|
// Populate any ENS names (in-place)
|
|
258
248
|
// const populated = await ethers.utils._TypedDataEncoder.resolveNames(domain, types, message, (name: string) => {
|
|
259
249
|
// return this.provider.resolveName(name)
|
|
260
250
|
// })
|
|
261
251
|
|
|
262
|
-
return this.provider.send(
|
|
263
|
-
|
|
252
|
+
return await this.provider.send(
|
|
253
|
+
'eth_signTypedData_v4',
|
|
264
254
|
[await this.getAddress(), ethers.utils._TypedDataEncoder.getPayload(domain, types, message)],
|
|
265
255
|
maybeChainId(chainId) || this.defaultChainId
|
|
266
256
|
)
|
|
@@ -269,16 +259,17 @@ export class Web3Signer extends Signer implements TypedDataSigner {
|
|
|
269
259
|
// sendTransaction matches implementation from ethers JsonRpcSigner for compatibility, but with
|
|
270
260
|
// multi-chain support.
|
|
271
261
|
async sendTransaction(
|
|
272
|
-
transaction: Deferrable<
|
|
273
|
-
chainId?: ChainIdLike
|
|
274
|
-
|
|
262
|
+
transaction: Deferrable<TransactionRequest>,
|
|
263
|
+
chainId?: ChainIdLike,
|
|
264
|
+
allSigners?: boolean
|
|
265
|
+
): Promise<TransactionResponse> {
|
|
275
266
|
const provider = await this.getSender(maybeChainId(chainId) || this.defaultChainId)
|
|
276
267
|
|
|
277
268
|
const tx = this.sendUncheckedTransaction(transaction, chainId).then(hash => {
|
|
278
269
|
return ethers.utils
|
|
279
270
|
.poll(
|
|
280
271
|
() => {
|
|
281
|
-
return provider!.getTransaction(hash).then((tx:
|
|
272
|
+
return provider!.getTransaction(hash).then((tx: TransactionResponse) => {
|
|
282
273
|
if (tx === null) {
|
|
283
274
|
return undefined
|
|
284
275
|
}
|
|
@@ -300,10 +291,11 @@ export class Web3Signer extends Signer implements TypedDataSigner {
|
|
|
300
291
|
// sendTransactionBatch is a convenience method to call sendTransaction in a batch format, allowing you to
|
|
301
292
|
// send multiple transaction as a single payload and just one on-chain transaction.
|
|
302
293
|
async sendTransactionBatch(
|
|
303
|
-
transactions: Deferrable<
|
|
304
|
-
chainId?: ChainIdLike
|
|
305
|
-
|
|
306
|
-
|
|
294
|
+
transactions: Deferrable<Forbid<TransactionRequest, 'wait'>[]>,
|
|
295
|
+
chainId?: ChainIdLike,
|
|
296
|
+
allSigners?: boolean
|
|
297
|
+
): Promise<TransactionResponse> {
|
|
298
|
+
const batch = await resolveArrayProperties<Forbid<TransactionRequest, 'wait'>[]>(transactions)
|
|
307
299
|
if (!batch || batch.length === 0) {
|
|
308
300
|
throw new Error('cannot send empty batch')
|
|
309
301
|
}
|
|
@@ -313,31 +305,33 @@ export class Web3Signer extends Signer implements TypedDataSigner {
|
|
|
313
305
|
throw new Error('transaction request expected for sendTransactionBatch, transaction response found')
|
|
314
306
|
}
|
|
315
307
|
|
|
316
|
-
const
|
|
317
|
-
|
|
308
|
+
const tx: TransactionRequest = { ...batch[0] }
|
|
309
|
+
if (batch.length > 1) {
|
|
310
|
+
tx.auxiliary = batch.splice(1)
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
return this.sendTransaction(tx, chainId, allSigners)
|
|
318
314
|
}
|
|
319
315
|
|
|
320
316
|
signTransactions(
|
|
321
|
-
transaction: Deferrable<
|
|
322
|
-
chainId?: ChainIdLike
|
|
323
|
-
|
|
317
|
+
transaction: Deferrable<TransactionRequest>,
|
|
318
|
+
chainId?: ChainIdLike,
|
|
319
|
+
allSigners?: boolean
|
|
320
|
+
): Promise<SignedTransactions> {
|
|
324
321
|
transaction = shallowCopy(transaction)
|
|
325
322
|
// TODO: transaction argument..? make sure to resolve any properties and serialize property before sending over
|
|
326
323
|
// the wire.. see sendUncheckedTransaction and resolveProperties
|
|
327
324
|
return this.provider.send('eth_signTransaction', [transaction], maybeChainId(chainId) || this.defaultChainId)
|
|
328
325
|
}
|
|
329
326
|
|
|
330
|
-
sendSignedTransactions(
|
|
331
|
-
signedTxs: commons.transaction.SignedTransactionBundle,
|
|
332
|
-
chainId?: ChainIdLike
|
|
333
|
-
): Promise<ethers.providers.TransactionResponse> {
|
|
327
|
+
sendSignedTransactions(signedTxs: SignedTransactions, chainId?: ChainIdLike): Promise<TransactionResponse> {
|
|
334
328
|
// sequence_relay
|
|
335
329
|
throw new Error('TODO')
|
|
336
330
|
}
|
|
337
331
|
|
|
338
332
|
// updateConfig..
|
|
339
333
|
// NOTE: this is not supported by the remote wallet by default.
|
|
340
|
-
async updateConfig(newConfig?:
|
|
334
|
+
async updateConfig(newConfig?: WalletConfig): Promise<[WalletConfig, TransactionResponse | undefined]> {
|
|
341
335
|
// sequence_updateConfig
|
|
342
336
|
const [config, tx] = await this.provider.send('sequence_updateConfig', [newConfig], this.defaultChainId)
|
|
343
337
|
if (tx === null) {
|
|
@@ -350,7 +344,7 @@ export class Web3Signer extends Signer implements TypedDataSigner {
|
|
|
350
344
|
|
|
351
345
|
// publishConfig..
|
|
352
346
|
// NOTE: this is not supported by the remote wallet by default.
|
|
353
|
-
async publishConfig(): Promise<
|
|
347
|
+
async publishConfig(): Promise<TransactionResponse | undefined> {
|
|
354
348
|
const provider = await this.getSender(this.defaultChainId)
|
|
355
349
|
|
|
356
350
|
const tx = await provider!.send('sequence_publishConfig', [])
|
|
@@ -391,7 +385,7 @@ export class Web3Signer extends Signer implements TypedDataSigner {
|
|
|
391
385
|
return this.signTypedData(domain, types, message, chainId, allSigners)
|
|
392
386
|
}
|
|
393
387
|
|
|
394
|
-
async sendUncheckedTransaction(transaction: Deferrable<
|
|
388
|
+
async sendUncheckedTransaction(transaction: Deferrable<TransactionRequest>, chainId?: ChainIdLike): Promise<string> {
|
|
395
389
|
transaction = shallowCopy(transaction)
|
|
396
390
|
|
|
397
391
|
const fromAddress = this.getAddress()
|
|
@@ -466,7 +460,7 @@ const allowedTransactionKeys: { [key: string]: boolean } = {
|
|
|
466
460
|
}
|
|
467
461
|
|
|
468
462
|
const hexlifyTransaction = (
|
|
469
|
-
transaction:
|
|
463
|
+
transaction: TransactionRequest,
|
|
470
464
|
allowExtra?: { [key: string]: boolean }
|
|
471
465
|
): { [key: string]: string } => {
|
|
472
466
|
// Check only allowed properties are given
|
|
@@ -519,9 +513,9 @@ const hexlifyTransaction = (
|
|
|
519
513
|
}
|
|
520
514
|
|
|
521
515
|
class UncheckedJsonRpcSigner extends Web3Signer {
|
|
522
|
-
sendTransaction(transaction: Deferrable<
|
|
516
|
+
sendTransaction(transaction: Deferrable<TransactionRequest>): Promise<TransactionResponse> {
|
|
523
517
|
return this.sendUncheckedTransaction(transaction).then(hash => {
|
|
524
|
-
return <
|
|
518
|
+
return <TransactionResponse>{
|
|
525
519
|
chainId: 0,
|
|
526
520
|
confirmations: 0,
|
|
527
521
|
data: '',
|
|
@@ -17,10 +17,9 @@ import {
|
|
|
17
17
|
TypedEventEmitter
|
|
18
18
|
} from '../types'
|
|
19
19
|
|
|
20
|
-
import { NetworkConfig, JsonRpcRequest, JsonRpcResponseCallback } from '@0xsequence/network'
|
|
20
|
+
import { NetworkConfig, WalletContext, JsonRpcRequest, JsonRpcResponseCallback, JsonRpcResponse } from '@0xsequence/network'
|
|
21
21
|
import { logger } from '@0xsequence/utils'
|
|
22
22
|
import { ethers } from 'ethers'
|
|
23
|
-
import { commons } from '@0xsequence/core'
|
|
24
23
|
|
|
25
24
|
export const PROVIDER_OPEN_TIMEOUT = 30000 // in ms
|
|
26
25
|
|
|
@@ -40,7 +39,7 @@ export abstract class BaseProviderTransport implements ProviderTransport {
|
|
|
40
39
|
protected connectPayload: ConnectDetails | undefined
|
|
41
40
|
protected accountsChangedPayload: { accounts: string[]; origin?: string } | undefined
|
|
42
41
|
protected networksPayload: NetworkConfig[] | undefined
|
|
43
|
-
protected walletContextPayload:
|
|
42
|
+
protected walletContextPayload: WalletContext | undefined
|
|
44
43
|
|
|
45
44
|
protected _sessionId?: string
|
|
46
45
|
protected _init: InitState
|
|
@@ -5,22 +5,23 @@ import {
|
|
|
5
5
|
ProviderMessageRequest,
|
|
6
6
|
EventType,
|
|
7
7
|
ProviderMessageResponse,
|
|
8
|
+
ProviderMessageTransport,
|
|
8
9
|
ProviderRpcError,
|
|
9
10
|
InitState,
|
|
10
11
|
ConnectDetails,
|
|
12
|
+
OpenWalletIntent,
|
|
11
13
|
WalletSession,
|
|
12
14
|
TransportSession
|
|
13
15
|
} from '../types'
|
|
14
16
|
|
|
15
17
|
import { WalletRequestHandler } from './wallet-request-handler'
|
|
16
18
|
|
|
17
|
-
import { NetworkConfig, JsonRpcRequest, JsonRpcResponseCallback } from '@0xsequence/network'
|
|
19
|
+
import { NetworkConfig, WalletContext, JsonRpcRequest, JsonRpcResponseCallback } from '@0xsequence/network'
|
|
18
20
|
import { logger, sanitizeAlphanumeric, sanitizeHost, sanitizeNumberString } from '@0xsequence/utils'
|
|
19
21
|
import { AuthorizationOptions } from '@0xsequence/auth'
|
|
20
22
|
|
|
21
23
|
import { PROVIDER_OPEN_TIMEOUT } from './base-provider-transport'
|
|
22
24
|
import { isBrowserExtension, LocalStorage } from '../utils'
|
|
23
|
-
import { commons } from '@0xsequence/core'
|
|
24
25
|
|
|
25
26
|
const TRANSPORT_SESSION_LS_KEY = '@sequence.transportSession'
|
|
26
27
|
|
|
@@ -69,7 +70,7 @@ export abstract class BaseWalletTransport implements WalletTransport {
|
|
|
69
70
|
}
|
|
70
71
|
})
|
|
71
72
|
|
|
72
|
-
this.walletRequestHandler.on('walletContext', (walletContext:
|
|
73
|
+
this.walletRequestHandler.on('walletContext', (walletContext: WalletContext) => {
|
|
73
74
|
if (!this.registered || !walletContext) return
|
|
74
75
|
this.notifyWalletContext(walletContext)
|
|
75
76
|
})
|
|
@@ -230,7 +231,7 @@ export abstract class BaseWalletTransport implements WalletTransport {
|
|
|
230
231
|
})
|
|
231
232
|
}
|
|
232
233
|
|
|
233
|
-
notifyWalletContext(walletContext:
|
|
234
|
+
notifyWalletContext(walletContext: WalletContext) {
|
|
234
235
|
this.sendMessage({
|
|
235
236
|
idx: -1,
|
|
236
237
|
type: EventType.WALLET_CONTEXT,
|
|
@@ -367,7 +368,7 @@ export abstract class BaseWalletTransport implements WalletTransport {
|
|
|
367
368
|
}
|
|
368
369
|
|
|
369
370
|
// ensure signer is ready
|
|
370
|
-
await this.walletRequestHandler.
|
|
371
|
+
await this.walletRequestHandler.getSigner()
|
|
371
372
|
|
|
372
373
|
// Notify open and proceed to prompt for connection if intended
|
|
373
374
|
if (!(await this.walletRequestHandler.isSignedIn())) {
|
|
@@ -385,9 +386,9 @@ export abstract class BaseWalletTransport implements WalletTransport {
|
|
|
385
386
|
let chainId: number | undefined = undefined
|
|
386
387
|
try {
|
|
387
388
|
if (networkId) {
|
|
388
|
-
chainId = this.walletRequestHandler.setDefaultNetwork(networkId)
|
|
389
|
+
chainId = await this.walletRequestHandler.setDefaultNetwork(networkId, false)
|
|
389
390
|
} else {
|
|
390
|
-
chainId = this.walletRequestHandler.
|
|
391
|
+
chainId = await this.walletRequestHandler.getChainId()
|
|
391
392
|
}
|
|
392
393
|
} catch (err) {
|
|
393
394
|
console.error(err)
|
|
@@ -422,9 +423,9 @@ export abstract class BaseWalletTransport implements WalletTransport {
|
|
|
422
423
|
let chainId: number | undefined = undefined
|
|
423
424
|
try {
|
|
424
425
|
if (networkId) {
|
|
425
|
-
chainId = this.walletRequestHandler.setDefaultNetwork(networkId)
|
|
426
|
+
chainId = await this.walletRequestHandler.setDefaultNetwork(networkId, false)
|
|
426
427
|
} else {
|
|
427
|
-
chainId = this.walletRequestHandler.
|
|
428
|
+
chainId = await this.walletRequestHandler.getChainId()
|
|
428
429
|
}
|
|
429
430
|
} catch (err) {
|
|
430
431
|
console.error(err)
|