@0xsequence/provider 1.1.1 → 1.1.3
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.dev.js +27 -21
- package/dist/0xsequence-provider.cjs.prod.js +27 -21
- package/dist/0xsequence-provider.esm.js +28 -22
- package/dist/declarations/src/client.d.ts +5 -5
- package/dist/declarations/src/init.d.ts +1 -1
- package/dist/declarations/src/provider.d.ts +3 -3
- package/dist/declarations/src/signer.d.ts +5 -5
- package/dist/declarations/src/transports/wallet-request-handler.d.ts +3 -3
- package/package.json +10 -10
- package/src/client.ts +76 -76
- package/src/extended.ts +3 -4
- package/src/init.ts +30 -27
- package/src/provider.ts +36 -66
- package/src/signer.ts +38 -54
- package/src/transports/base-wallet-transport.ts +6 -0
- package/src/transports/extension-transport/extension-message-handler.ts +4 -1
- package/src/transports/extension-transport/index.ts +1 -1
- package/src/transports/mux-transport/mux-message-provider.ts +15 -14
- package/src/transports/proxy-transport/proxy-message-channel.ts +0 -1
- package/src/transports/proxy-transport/proxy-message-provider.ts +12 -8
- package/src/transports/unreal-transport/index.ts +1 -1
- package/src/transports/unreal-transport/overridelogs.ts +1 -3
- package/src/transports/wallet-request-handler.ts +77 -52
- package/src/transports/window-transport/window-message-provider.ts +4 -3
- package/src/types.ts +25 -12
- package/src/utils/index.ts +2 -12
- package/src/utils.ts +12 -13
package/src/signer.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { ethers } from
|
|
1
|
+
import { ethers } from 'ethers'
|
|
2
2
|
|
|
3
|
-
import { SequenceProvider, SingleNetworkSequenceProvider } from
|
|
4
|
-
import { SequenceClient } from
|
|
5
|
-
import { commons } from
|
|
6
|
-
import { ChainIdLike, NetworkConfig } from
|
|
7
|
-
import { resolveArrayProperties } from
|
|
8
|
-
import { WalletUtils } from
|
|
9
|
-
import { OptionalChainIdLike, OptionalEIP6492 } from
|
|
3
|
+
import { SequenceProvider, SingleNetworkSequenceProvider } from './provider'
|
|
4
|
+
import { SequenceClient } from './client'
|
|
5
|
+
import { commons } from '@0xsequence/core'
|
|
6
|
+
import { ChainIdLike, NetworkConfig } from '@0xsequence/network'
|
|
7
|
+
import { resolveArrayProperties } from './utils'
|
|
8
|
+
import { WalletUtils } from './utils/index'
|
|
9
|
+
import { OptionalChainIdLike, OptionalEIP6492 } from './types'
|
|
10
10
|
|
|
11
11
|
export interface ISequenceSigner extends ethers.Signer {
|
|
12
12
|
getProvider(): SequenceProvider
|
|
@@ -20,10 +20,7 @@ export interface ISequenceSigner extends ethers.Signer {
|
|
|
20
20
|
getWalletConfig(chainId?: ChainIdLike): Promise<commons.config.Config>
|
|
21
21
|
getNetworks(): Promise<NetworkConfig[]>
|
|
22
22
|
|
|
23
|
-
signMessage(
|
|
24
|
-
message: ethers.BytesLike,
|
|
25
|
-
options?: OptionalChainIdLike & OptionalEIP6492
|
|
26
|
-
): Promise<string>
|
|
23
|
+
signMessage(message: ethers.BytesLike, options?: OptionalChainIdLike & OptionalEIP6492): Promise<string>
|
|
27
24
|
|
|
28
25
|
signTypedData(
|
|
29
26
|
domain: ethers.TypedDataDomain,
|
|
@@ -36,10 +33,9 @@ export interface ISequenceSigner extends ethers.Signer {
|
|
|
36
33
|
// the signer, and finally sends it to the relayer for submission to an Ethereum network.
|
|
37
34
|
// It supports any kind of transaction, including regular ethers transactions, and Sequence transactions.
|
|
38
35
|
sendTransaction(
|
|
39
|
-
transaction:
|
|
40
|
-
ethers.utils.Deferrable<ethers.providers.TransactionRequest>[]
|
|
41
|
-
ethers.utils.Deferrable<ethers.providers.TransactionRequest
|
|
42
|
-
),
|
|
36
|
+
transaction:
|
|
37
|
+
| ethers.utils.Deferrable<ethers.providers.TransactionRequest>[]
|
|
38
|
+
| ethers.utils.Deferrable<ethers.providers.TransactionRequest>,
|
|
43
39
|
options?: OptionalChainIdLike
|
|
44
40
|
): Promise<commons.transaction.TransactionResponse>
|
|
45
41
|
|
|
@@ -56,10 +52,10 @@ export class SequenceSigner implements ISequenceSigner {
|
|
|
56
52
|
return this.provider.utils
|
|
57
53
|
}
|
|
58
54
|
|
|
59
|
-
constructor
|
|
55
|
+
constructor(
|
|
60
56
|
public client: SequenceClient,
|
|
61
57
|
public provider: SequenceProvider
|
|
62
|
-
) {
|
|
58
|
+
) {}
|
|
63
59
|
|
|
64
60
|
async getAddress(): Promise<string> {
|
|
65
61
|
return this.client.getAddress()
|
|
@@ -69,7 +65,7 @@ export class SequenceSigner implements ISequenceSigner {
|
|
|
69
65
|
// it exists to maintain compatibility with ethers.Signer
|
|
70
66
|
connect(provider: ethers.providers.Provider): SequenceSigner {
|
|
71
67
|
if (!SequenceProvider.is(provider)) {
|
|
72
|
-
throw new Error(
|
|
68
|
+
throw new Error('SequenceSigner can only be connected to a SequenceProvider')
|
|
73
69
|
}
|
|
74
70
|
|
|
75
71
|
return new SequenceSigner(this.client, provider)
|
|
@@ -90,7 +86,7 @@ export class SequenceSigner implements ISequenceSigner {
|
|
|
90
86
|
if (!this.singleNetworkSigners[useChainId]) {
|
|
91
87
|
this.singleNetworkSigners[useChainId] = new SingleNetworkSequenceSigner(this.client, this.provider, useChainId)
|
|
92
88
|
}
|
|
93
|
-
|
|
89
|
+
|
|
94
90
|
return this.singleNetworkSigners[useChainId]
|
|
95
91
|
}
|
|
96
92
|
|
|
@@ -103,10 +99,7 @@ export class SequenceSigner implements ISequenceSigner {
|
|
|
103
99
|
return this.provider.toChainId(chainId) || this.client.getChainId()
|
|
104
100
|
}
|
|
105
101
|
|
|
106
|
-
async signMessage(
|
|
107
|
-
message: ethers.BytesLike,
|
|
108
|
-
options?: OptionalChainIdLike & OptionalEIP6492
|
|
109
|
-
): Promise<string> {
|
|
102
|
+
async signMessage(message: ethers.BytesLike, options?: OptionalChainIdLike & OptionalEIP6492): Promise<string> {
|
|
110
103
|
const { eip6492 = true } = options || {}
|
|
111
104
|
const chainId = this.useChainId(options?.chainId)
|
|
112
105
|
return this.client.signMessage(message, { eip6492, chainId })
|
|
@@ -132,10 +125,9 @@ export class SequenceSigner implements ISequenceSigner {
|
|
|
132
125
|
}
|
|
133
126
|
|
|
134
127
|
async sendTransaction(
|
|
135
|
-
transaction:
|
|
136
|
-
ethers.utils.Deferrable<ethers.providers.TransactionRequest>[]
|
|
137
|
-
ethers.utils.Deferrable<ethers.providers.TransactionRequest
|
|
138
|
-
),
|
|
128
|
+
transaction:
|
|
129
|
+
| ethers.utils.Deferrable<ethers.providers.TransactionRequest>[]
|
|
130
|
+
| ethers.utils.Deferrable<ethers.providers.TransactionRequest>,
|
|
139
131
|
options?: OptionalChainIdLike
|
|
140
132
|
) {
|
|
141
133
|
const chainId = this.useChainId(options?.chainId)
|
|
@@ -144,10 +136,13 @@ export class SequenceSigner implements ISequenceSigner {
|
|
|
144
136
|
const provider = this.getProvider(chainId)
|
|
145
137
|
|
|
146
138
|
try {
|
|
147
|
-
return await ethers.utils.poll(
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
139
|
+
return (await ethers.utils.poll(
|
|
140
|
+
async () => {
|
|
141
|
+
const tx = await provider.getTransaction(txHash)
|
|
142
|
+
return tx ? provider._wrapTransaction(tx, txHash) : undefined
|
|
143
|
+
},
|
|
144
|
+
{ onceBlock: provider }
|
|
145
|
+
)) as ethers.providers.TransactionResponse
|
|
151
146
|
} catch (err) {
|
|
152
147
|
err.transactionHash = txHash
|
|
153
148
|
throw err
|
|
@@ -163,10 +158,7 @@ export class SequenceSigner implements ISequenceSigner {
|
|
|
163
158
|
return this.client.getNetworks()
|
|
164
159
|
}
|
|
165
160
|
|
|
166
|
-
async getBalance(
|
|
167
|
-
blockTag?: ethers.providers.BlockTag | undefined,
|
|
168
|
-
optionals?: OptionalChainIdLike
|
|
169
|
-
): Promise<ethers.BigNumber> {
|
|
161
|
+
async getBalance(blockTag?: ethers.providers.BlockTag | undefined, optionals?: OptionalChainIdLike): Promise<ethers.BigNumber> {
|
|
170
162
|
const provider = this.getProvider(optionals?.chainId)
|
|
171
163
|
return provider.getBalance(this.getAddress(), blockTag)
|
|
172
164
|
}
|
|
@@ -219,19 +211,19 @@ export class SequenceSigner implements ISequenceSigner {
|
|
|
219
211
|
populateTransaction(
|
|
220
212
|
_transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest>
|
|
221
213
|
): Promise<ethers.providers.TransactionRequest> {
|
|
222
|
-
throw new Error(
|
|
214
|
+
throw new Error('SequenceSigner does not support populateTransaction')
|
|
223
215
|
}
|
|
224
216
|
|
|
225
217
|
checkTransaction(
|
|
226
218
|
_transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest>
|
|
227
219
|
): ethers.utils.Deferrable<ethers.providers.TransactionRequest> {
|
|
228
|
-
throw new Error(
|
|
220
|
+
throw new Error('SequenceSigner does not support checkTransaction')
|
|
229
221
|
}
|
|
230
222
|
|
|
231
223
|
getTransactionCount(_blockTag?: ethers.providers.BlockTag | undefined): Promise<number> {
|
|
232
224
|
// We could try returning the sequence nonce here
|
|
233
225
|
// but we aren't sure how ethers will use this nonce
|
|
234
|
-
throw new Error(
|
|
226
|
+
throw new Error('SequenceSigner does not support getTransactionCount')
|
|
235
227
|
}
|
|
236
228
|
|
|
237
229
|
signTransaction(_transaction: ethers.utils.Deferrable<commons.transaction.Transactionish>): Promise<string> {
|
|
@@ -239,31 +231,27 @@ export class SequenceSigner implements ISequenceSigner {
|
|
|
239
231
|
// but first we need a way of serializing these signed transactions
|
|
240
232
|
// and it could lead to more trouble, because the dapp could try to send this transaction
|
|
241
233
|
// using a different provider, which would fail.
|
|
242
|
-
throw new Error(
|
|
234
|
+
throw new Error('SequenceWallet does not support signTransaction, use sendTransaction instead.')
|
|
243
235
|
}
|
|
244
236
|
|
|
245
237
|
static is(cand: any): cand is SequenceSigner {
|
|
246
|
-
return
|
|
247
|
-
cand &&
|
|
248
|
-
typeof cand === "object" &&
|
|
249
|
-
cand._isSequenceSigner === true
|
|
250
|
-
)
|
|
238
|
+
return cand && typeof cand === 'object' && cand._isSequenceSigner === true
|
|
251
239
|
}
|
|
252
240
|
}
|
|
253
241
|
|
|
254
242
|
/**
|
|
255
243
|
* This is the same provider, but it only allows a single network at a time.
|
|
256
244
|
* the network defined by the constructor is the only one that can be used.
|
|
257
|
-
*
|
|
245
|
+
*
|
|
258
246
|
* Attempting to call any method with a different network will throw an error.
|
|
259
247
|
* Attempting to change the network of this provider will throw an error.
|
|
260
|
-
*
|
|
248
|
+
*
|
|
261
249
|
* NOTICE: These networks won't support ENS unless they are the mainnet.
|
|
262
250
|
*/
|
|
263
251
|
export class SingleNetworkSequenceSigner extends SequenceSigner {
|
|
264
252
|
readonly _isSingleNetworkSequenceSigner = true
|
|
265
253
|
|
|
266
|
-
constructor
|
|
254
|
+
constructor(
|
|
267
255
|
client: SequenceClient,
|
|
268
256
|
provider: SequenceProvider,
|
|
269
257
|
public readonly chainId: ChainIdLike
|
|
@@ -302,15 +290,11 @@ export class SingleNetworkSequenceSigner extends SequenceSigner {
|
|
|
302
290
|
if (this._useChainId(chainId) !== this.chainId) {
|
|
303
291
|
throw new Error(`Unreachable code`)
|
|
304
292
|
}
|
|
305
|
-
|
|
293
|
+
|
|
306
294
|
return this
|
|
307
295
|
}
|
|
308
296
|
|
|
309
297
|
static is(cand: any): cand is SingleNetworkSequenceSigner {
|
|
310
|
-
return
|
|
311
|
-
cand &&
|
|
312
|
-
typeof cand === "object" &&
|
|
313
|
-
cand._isSingleNetworkSequenceSigner === true
|
|
314
|
-
)
|
|
298
|
+
return cand && typeof cand === 'object' && cand._isSingleNetworkSequenceSigner === true
|
|
315
299
|
}
|
|
316
300
|
}
|
|
@@ -372,6 +372,12 @@ export abstract class BaseWalletTransport implements WalletTransport {
|
|
|
372
372
|
connectOptions.app = sanitizeAlphanumeric(connectOptions.app)
|
|
373
373
|
}
|
|
374
374
|
|
|
375
|
+
if (connectOptions.networkId) {
|
|
376
|
+
networkId = connectOptions.networkId
|
|
377
|
+
} else if (networkId) {
|
|
378
|
+
connectOptions.networkId = networkId
|
|
379
|
+
}
|
|
380
|
+
|
|
375
381
|
// Set connect options on the walletRequestHandler as our primary
|
|
376
382
|
// wallet controller, and fall back to networkId if necessary
|
|
377
383
|
this.walletRequestHandler.setConnectOptions(connectOptions)
|
|
@@ -9,7 +9,10 @@ export const CHANNEL_ID = 'sequence-extension-message-handler'
|
|
|
9
9
|
export class ExtensionMessageHandler extends BaseWalletTransport {
|
|
10
10
|
private port: any
|
|
11
11
|
|
|
12
|
-
constructor(
|
|
12
|
+
constructor(
|
|
13
|
+
walletRequestHandler: WalletRequestHandler,
|
|
14
|
+
public runtime: Runtime.Static
|
|
15
|
+
) {
|
|
13
16
|
super(walletRequestHandler)
|
|
14
17
|
this._init = InitState.OK
|
|
15
18
|
}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
-
ProviderMessage,
|
|
3
|
-
|
|
2
|
+
ProviderMessage,
|
|
3
|
+
ProviderTransport,
|
|
4
|
+
ProviderEventTypes,
|
|
5
|
+
ProviderMessageRequest,
|
|
6
|
+
ProviderMessageResponse,
|
|
7
|
+
WalletSession,
|
|
8
|
+
OpenWalletIntent,
|
|
9
|
+
ConnectDetails
|
|
4
10
|
} from '../../types'
|
|
5
11
|
|
|
6
12
|
import { JsonRpcRequest, JsonRpcResponseCallback } from '@0xsequence/network'
|
|
@@ -40,19 +46,15 @@ export function isMuxTransportTemplate(obj: any): obj is MuxTransportTemplate {
|
|
|
40
46
|
return (
|
|
41
47
|
obj &&
|
|
42
48
|
typeof obj === 'object' &&
|
|
43
|
-
(
|
|
44
|
-
(obj.windowTransport && typeof obj.windowTransport === 'object') ||
|
|
49
|
+
((obj.windowTransport && typeof obj.windowTransport === 'object') ||
|
|
45
50
|
(obj.proxyTransport && typeof obj.proxyTransport === 'object') ||
|
|
46
51
|
(obj.extensionTransport && typeof obj.extensionTransport === 'object') ||
|
|
47
|
-
(obj.unrealTransport && typeof obj.unrealTransport === 'object')
|
|
48
|
-
|
|
49
|
-
(
|
|
50
|
-
// One of the transports must be enabled
|
|
51
|
-
(obj.windowTransport && obj.windowTransport.enabled) ||
|
|
52
|
+
(obj.unrealTransport && typeof obj.unrealTransport === 'object')) &&
|
|
53
|
+
// One of the transports must be enabled
|
|
54
|
+
((obj.windowTransport && obj.windowTransport.enabled) ||
|
|
52
55
|
(obj.proxyTransport && obj.proxyTransport.enabled) ||
|
|
53
56
|
(obj.extensionTransport && obj.extensionTransport.enabled) ||
|
|
54
|
-
(obj.unrealTransport && obj.unrealTransport.enabled)
|
|
55
|
-
)
|
|
57
|
+
(obj.unrealTransport && obj.unrealTransport.enabled))
|
|
56
58
|
)
|
|
57
59
|
}
|
|
58
60
|
|
|
@@ -81,7 +83,7 @@ export class MuxMessageProvider implements ProviderTransport {
|
|
|
81
83
|
if (template.extensionTransport?.enabled) {
|
|
82
84
|
const extensionMessageProvider = new ExtensionMessageProvider(template.extensionTransport.runtime)
|
|
83
85
|
muxMessageProvider.add(extensionMessageProvider)
|
|
84
|
-
|
|
86
|
+
|
|
85
87
|
// NOTE/REVIEW: see note in mux-message-provider
|
|
86
88
|
//
|
|
87
89
|
// We don't add the extensionMessageProvider here because we don't send requests to it anyways, we seem to
|
|
@@ -190,7 +192,7 @@ export class MuxMessageProvider implements ProviderTransport {
|
|
|
190
192
|
if (this.provider) {
|
|
191
193
|
return this.provider.emit(event, ...args)
|
|
192
194
|
}
|
|
193
|
-
for (let i=0; i < this.messageProviders.length; i++) {
|
|
195
|
+
for (let i = 0; i < this.messageProviders.length; i++) {
|
|
194
196
|
this.messageProviders[i].emit(event, ...args)
|
|
195
197
|
}
|
|
196
198
|
return true
|
|
@@ -244,5 +246,4 @@ export class MuxMessageProvider implements ProviderTransport {
|
|
|
244
246
|
}
|
|
245
247
|
throw new Error('impossible state, wallet must be opened first')
|
|
246
248
|
}
|
|
247
|
-
|
|
248
249
|
}
|
|
@@ -21,7 +21,6 @@ export class ProxyMessageChannelPort implements ProviderMessageTransport {
|
|
|
21
21
|
conn: ProviderMessageTransport
|
|
22
22
|
events: TypedEventEmitter<ProxyEventTypes> = new EventEmitter() as TypedEventEmitter<ProxyEventTypes>
|
|
23
23
|
|
|
24
|
-
|
|
25
24
|
// handle messages which hit this port
|
|
26
25
|
handleMessage = (message: ProviderMessage<any>): void => {
|
|
27
26
|
throw new Error('ProxyMessageChannelPort is not registered')
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { BaseProviderTransport } from '../base-provider-transport'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
ProviderMessage, OpenState, OpenWalletIntent, EventType, InitState
|
|
5
|
-
} from '../../types'
|
|
3
|
+
import { ProviderMessage, OpenState, OpenWalletIntent, EventType, InitState } from '../../types'
|
|
6
4
|
|
|
7
5
|
import { ProxyMessageChannelPort, ProxyEventTypes } from './proxy-message-channel'
|
|
8
6
|
|
|
9
7
|
export class ProxyMessageProvider extends BaseProviderTransport {
|
|
10
|
-
|
|
11
8
|
private port: ProxyMessageChannelPort
|
|
12
|
-
|
|
9
|
+
|
|
13
10
|
constructor(port: ProxyMessageChannelPort) {
|
|
14
11
|
super()
|
|
15
12
|
this.state = OpenState.CLOSED
|
|
@@ -58,8 +55,13 @@ export class ProxyMessageProvider extends BaseProviderTransport {
|
|
|
58
55
|
const sessionId = `${performance.now()}`
|
|
59
56
|
this._sessionId = sessionId
|
|
60
57
|
this.sendMessage({
|
|
61
|
-
idx: -1,
|
|
62
|
-
|
|
58
|
+
idx: -1,
|
|
59
|
+
type: EventType.OPEN,
|
|
60
|
+
data: {
|
|
61
|
+
path,
|
|
62
|
+
intent,
|
|
63
|
+
networkId,
|
|
64
|
+
sessionId
|
|
63
65
|
}
|
|
64
66
|
})
|
|
65
67
|
}
|
|
@@ -67,7 +69,9 @@ export class ProxyMessageProvider extends BaseProviderTransport {
|
|
|
67
69
|
|
|
68
70
|
closeWallet() {
|
|
69
71
|
this.sendMessage({
|
|
70
|
-
idx: -1,
|
|
72
|
+
idx: -1,
|
|
73
|
+
type: EventType.CLOSE,
|
|
74
|
+
data: null
|
|
71
75
|
})
|
|
72
76
|
this.close()
|
|
73
77
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './unreal-message-provider'
|
|
2
|
-
export * from './unreal-message-handler'
|
|
2
|
+
export * from './unreal-message-handler'
|
|
@@ -30,7 +30,5 @@ export function overrideLogs(side: 'dapp' | 'wallet') {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
function stringify(things: unknown[]): string {
|
|
33
|
-
return things
|
|
34
|
-
.map(a => (typeof a === 'object' ? (a instanceof Error ? a.message : JSON.stringify(a)) : String(a)))
|
|
35
|
-
.join(' ')
|
|
33
|
+
return things.map(a => (typeof a === 'object' ? (a instanceof Error ? a.message : JSON.stringify(a)) : String(a))).join(' ')
|
|
36
34
|
}
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import { Account, AccountStatus } from '@0xsequence/account'
|
|
2
2
|
import { signAuthorization, AuthorizationOptions } from '@0xsequence/auth'
|
|
3
3
|
import { commons } from '@0xsequence/core'
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
ChainId,
|
|
6
|
+
findSupportedNetwork,
|
|
7
|
+
JsonRpcHandler,
|
|
8
|
+
JsonRpcRequest,
|
|
9
|
+
JsonRpcResponse,
|
|
10
|
+
JsonRpcResponseCallback,
|
|
11
|
+
NetworkConfig
|
|
12
|
+
} from '@0xsequence/network'
|
|
5
13
|
import { logger, TypedData } from '@0xsequence/utils'
|
|
6
14
|
import { BigNumber, ethers, providers } from 'ethers'
|
|
7
15
|
import { EventEmitter2 as EventEmitter } from 'eventemitter2'
|
|
@@ -9,19 +17,20 @@ import { EventEmitter2 as EventEmitter } from 'eventemitter2'
|
|
|
9
17
|
import { fromExtended } from '../extended'
|
|
10
18
|
import { validateTransactionRequest } from '../transactions'
|
|
11
19
|
import {
|
|
12
|
-
ProviderMessageRequest,
|
|
13
|
-
ProviderMessageResponse,
|
|
14
|
-
ProviderMessageRequestHandler,
|
|
15
|
-
MessageToSign,
|
|
16
|
-
ProviderRpcError,
|
|
17
|
-
ConnectOptions,
|
|
18
20
|
ConnectDetails,
|
|
19
|
-
|
|
20
|
-
WalletSession,
|
|
21
|
-
OpenWalletIntent,
|
|
21
|
+
ConnectOptions,
|
|
22
22
|
ErrSignedInRequired,
|
|
23
|
+
MessageToSign,
|
|
24
|
+
NetworkedConnectOptions,
|
|
25
|
+
OpenWalletIntent,
|
|
26
|
+
PromptConnectDetails,
|
|
23
27
|
ProviderEventTypes,
|
|
24
|
-
|
|
28
|
+
ProviderMessageRequest,
|
|
29
|
+
ProviderMessageRequestHandler,
|
|
30
|
+
ProviderMessageResponse,
|
|
31
|
+
ProviderRpcError,
|
|
32
|
+
TypedEventEmitter,
|
|
33
|
+
WalletSession
|
|
25
34
|
} from '../types'
|
|
26
35
|
import { prefixEIP191Message } from '../utils'
|
|
27
36
|
|
|
@@ -51,11 +60,7 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
|
|
|
51
60
|
|
|
52
61
|
onConnectOptionsChange: ((connectOptions: ConnectOptions | undefined) => void) | undefined = undefined
|
|
53
62
|
|
|
54
|
-
constructor(
|
|
55
|
-
account: Account | null | undefined,
|
|
56
|
-
prompter: WalletUserPrompter | null,
|
|
57
|
-
networks: NetworkConfig[]
|
|
58
|
-
) {
|
|
63
|
+
constructor(account: Account | null | undefined, prompter: WalletUserPrompter | null, networks: NetworkConfig[]) {
|
|
59
64
|
this.account = account
|
|
60
65
|
this.prompter = prompter
|
|
61
66
|
this.networks = networks
|
|
@@ -96,7 +101,7 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
|
|
|
96
101
|
this.notifyClose()
|
|
97
102
|
}
|
|
98
103
|
}
|
|
99
|
-
|
|
104
|
+
|
|
100
105
|
if (defaultNetworkId && this.defaultChainId() !== defaultNetworkId) {
|
|
101
106
|
await this.prompter?.promptChangeNetwork(defaultNetworkId)
|
|
102
107
|
}
|
|
@@ -129,7 +134,7 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
|
|
|
129
134
|
})
|
|
130
135
|
}
|
|
131
136
|
|
|
132
|
-
async connect(options?:
|
|
137
|
+
async connect(options?: NetworkedConnectOptions): Promise<ConnectDetails> {
|
|
133
138
|
if (!this.account) {
|
|
134
139
|
return {
|
|
135
140
|
connected: false,
|
|
@@ -138,11 +143,12 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
|
|
|
138
143
|
}
|
|
139
144
|
}
|
|
140
145
|
|
|
141
|
-
const
|
|
146
|
+
const networkId = options?.networkId ?? this.defaultChainId() ?? ChainId.MAINNET
|
|
147
|
+
const chainId = findSupportedNetwork(networkId)!.chainId
|
|
142
148
|
|
|
143
149
|
const connectDetails: ConnectDetails = {
|
|
144
150
|
connected: true,
|
|
145
|
-
chainId: ethers.
|
|
151
|
+
chainId: ethers.utils.hexValue(chainId)
|
|
146
152
|
}
|
|
147
153
|
|
|
148
154
|
if (options && options.authorize) {
|
|
@@ -317,13 +323,20 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
|
|
|
317
323
|
const sequenceVerified = request.method === 'sequence_sign'
|
|
318
324
|
if (this.prompter === null) {
|
|
319
325
|
// prompter is null, so we'll sign from here
|
|
320
|
-
sig = await account.signMessage(
|
|
326
|
+
sig = await account.signMessage(
|
|
327
|
+
prefixedMessage,
|
|
328
|
+
chainId ?? this.defaultChainId(),
|
|
329
|
+
sequenceVerified ? 'eip6492' : 'ignore'
|
|
330
|
+
)
|
|
321
331
|
} else {
|
|
322
|
-
sig = await this.prompter.promptSignMessage(
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
332
|
+
sig = await this.prompter.promptSignMessage(
|
|
333
|
+
{
|
|
334
|
+
chainId: chainId,
|
|
335
|
+
message: prefixedMessage,
|
|
336
|
+
eip6492: sequenceVerified
|
|
337
|
+
},
|
|
338
|
+
this.connectOptions
|
|
339
|
+
)
|
|
327
340
|
}
|
|
328
341
|
|
|
329
342
|
if (sig && sig.length > 0) {
|
|
@@ -362,13 +375,22 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
|
|
|
362
375
|
const sequenceVerified = request.method === 'sequence_signTypedData_v4'
|
|
363
376
|
if (this.prompter === null) {
|
|
364
377
|
// prompter is null, so we'll sign from here
|
|
365
|
-
sig = await account.signTypedData(
|
|
378
|
+
sig = await account.signTypedData(
|
|
379
|
+
typedData.domain,
|
|
380
|
+
typedData.types,
|
|
381
|
+
typedData.message,
|
|
382
|
+
chainId ?? this.defaultChainId(),
|
|
383
|
+
sequenceVerified ? 'eip6492' : 'ignore'
|
|
384
|
+
)
|
|
366
385
|
} else {
|
|
367
|
-
sig = await this.prompter.promptSignMessage(
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
386
|
+
sig = await this.prompter.promptSignMessage(
|
|
387
|
+
{
|
|
388
|
+
chainId: chainId,
|
|
389
|
+
typedData: typedData,
|
|
390
|
+
eip6492: sequenceVerified
|
|
391
|
+
},
|
|
392
|
+
this.connectOptions
|
|
393
|
+
)
|
|
372
394
|
}
|
|
373
395
|
|
|
374
396
|
if (sig && sig.length > 0) {
|
|
@@ -382,17 +404,16 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
|
|
|
382
404
|
|
|
383
405
|
case 'eth_sendTransaction': {
|
|
384
406
|
// https://eth.wiki/json-rpc/API#eth_sendtransaction
|
|
385
|
-
const transactionParams = fromExtended(request.params![0])
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
})
|
|
407
|
+
const transactionParams = fromExtended(request.params![0]).map(tx => {
|
|
408
|
+
// eth_sendTransaction uses 'gas'
|
|
409
|
+
// ethers and sequence use 'gasLimit'
|
|
410
|
+
if ('gas' in tx && tx.gasLimit === undefined) {
|
|
411
|
+
tx.gasLimit = tx.gas as any
|
|
412
|
+
delete tx.gas
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
return tx
|
|
416
|
+
})
|
|
396
417
|
|
|
397
418
|
validateTransactionRequest(account.address, transactionParams)
|
|
398
419
|
|
|
@@ -539,10 +560,12 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
|
|
|
539
560
|
if (chainId) {
|
|
540
561
|
response.result = [(await account.status(chainId)).onChain.config]
|
|
541
562
|
} else {
|
|
542
|
-
response.result = await Promise.all(
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
563
|
+
response.result = await Promise.all(
|
|
564
|
+
account.networks.map(async network => {
|
|
565
|
+
const status = await account.status(network.chainId)
|
|
566
|
+
return status.onChain.config
|
|
567
|
+
})
|
|
568
|
+
)
|
|
546
569
|
}
|
|
547
570
|
break
|
|
548
571
|
}
|
|
@@ -554,10 +577,12 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
|
|
|
554
577
|
if (chainId) {
|
|
555
578
|
response.result = [getLegacyWalletState(chainId, await account.status(chainId))]
|
|
556
579
|
} else {
|
|
557
|
-
response.result = await Promise.all(
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
580
|
+
response.result = await Promise.all(
|
|
581
|
+
account.networks.map(async network => {
|
|
582
|
+
const status = await account.status(network.chainId)
|
|
583
|
+
return getLegacyWalletState(network.chainId, status)
|
|
584
|
+
})
|
|
585
|
+
)
|
|
561
586
|
}
|
|
562
587
|
break
|
|
563
588
|
}
|
|
@@ -709,7 +734,7 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
|
|
|
709
734
|
walletContext: this.account.contexts,
|
|
710
735
|
accountAddress: this.account.address,
|
|
711
736
|
// The dapp shouldn't access the relayer directly, and the provider (as an object) is not serializable.
|
|
712
|
-
networks: this.account.networks.map(
|
|
737
|
+
networks: this.account.networks.map(n => ({ ...n, provider: undefined, relayer: undefined }))
|
|
713
738
|
}
|
|
714
739
|
}
|
|
715
740
|
|
|
@@ -88,9 +88,10 @@ export class WindowMessageProvider extends BaseProviderTransport {
|
|
|
88
88
|
// when connecting to the wallet, however, this will be verified and enforced
|
|
89
89
|
// on the wallet-side, so if a dapp provides the wrong origin, it will be dropped.
|
|
90
90
|
if (intent.type === 'connect') {
|
|
91
|
-
if (!intent.options)
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
if (!intent.options)
|
|
92
|
+
intent.options = {
|
|
93
|
+
app: window.location.origin
|
|
94
|
+
}
|
|
94
95
|
|
|
95
96
|
// skip setting origin host if we're in an browser extension execution context
|
|
96
97
|
// allow origin that is passed in
|
package/src/types.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { ETHAuthProof as AuthETHAuthProof } from '@0xsequence/auth'
|
|
2
2
|
import { commons } from '@0xsequence/core'
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
ChainIdLike,
|
|
5
|
+
JsonRpcHandler,
|
|
6
|
+
JsonRpcRequest,
|
|
7
|
+
JsonRpcResponse,
|
|
8
|
+
NetworkConfig,
|
|
9
|
+
ProviderRpcError as NetworkProviderRpcError
|
|
10
|
+
} from '@0xsequence/network'
|
|
4
11
|
import { TypedData } from '@0xsequence/utils'
|
|
5
12
|
|
|
6
13
|
export interface ProviderTransport extends JsonRpcHandler, ProviderMessageTransport, ProviderMessageRequestHandler {
|
|
@@ -185,7 +192,7 @@ export interface NetworkedConnectOptions extends ConnectOptions {
|
|
|
185
192
|
/** chainId is the chainId to connect to. If not specified, the default chainId
|
|
186
193
|
* will be used. This does not define a default chain id, it is only used for the connect
|
|
187
194
|
* authorization signature. */
|
|
188
|
-
networkId?: string | number
|
|
195
|
+
networkId?: string | number
|
|
189
196
|
}
|
|
190
197
|
|
|
191
198
|
/** Options to further customize the wallet experience. */
|
|
@@ -329,19 +336,25 @@ export interface TypedEventEmitter<Events> {
|
|
|
329
336
|
|
|
330
337
|
type Arguments<T> = [T] extends [(...args: infer U) => any] ? U : [T] extends [void] ? [] : [T]
|
|
331
338
|
|
|
332
|
-
export type OptionalChainIdLike =
|
|
333
|
-
|
|
334
|
-
|
|
339
|
+
export type OptionalChainIdLike =
|
|
340
|
+
| {
|
|
341
|
+
chainId?: ChainIdLike
|
|
342
|
+
}
|
|
343
|
+
| undefined
|
|
335
344
|
|
|
336
|
-
export type OptionalChainId =
|
|
337
|
-
|
|
338
|
-
|
|
345
|
+
export type OptionalChainId =
|
|
346
|
+
| {
|
|
347
|
+
chainId?: number
|
|
348
|
+
}
|
|
349
|
+
| undefined
|
|
339
350
|
|
|
340
|
-
export type OptionalEIP6492 =
|
|
341
|
-
|
|
342
|
-
|
|
351
|
+
export type OptionalEIP6492 =
|
|
352
|
+
| {
|
|
353
|
+
eip6492?: boolean
|
|
354
|
+
}
|
|
355
|
+
| undefined
|
|
343
356
|
|
|
344
357
|
// This is required by viem, it expects a provider to have an EIP-1193 compliant `request` attribute.
|
|
345
358
|
export interface EIP1193Provider {
|
|
346
|
-
request: (request: { method: string
|
|
359
|
+
request: (request: { method: string; params?: Array<any> }) => Promise<any>
|
|
347
360
|
}
|