@0xsequence/provider 1.10.15 → 2.0.1
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 +663 -653
- package/dist/0xsequence-provider.cjs.prod.js +663 -653
- package/dist/0xsequence-provider.esm.js +667 -657
- package/dist/declarations/src/client.d.ts +7 -3
- package/dist/declarations/src/provider.d.ts +31 -22
- package/dist/declarations/src/signer.d.ts +15 -14
- package/dist/declarations/src/transports/base-provider-transport.d.ts +6 -2
- package/dist/declarations/src/transports/base-wallet-transport.d.ts +6 -2
- package/dist/declarations/src/transports/mux-transport/mux-message-provider.d.ts +5 -2
- package/dist/declarations/src/transports/wallet-request-handler.d.ts +7 -6
- package/dist/declarations/src/types.d.ts +6 -11
- package/dist/declarations/src/utils/index.d.ts +3 -3
- package/dist/declarations/src/utils.d.ts +7 -7
- package/package.json +12 -12
- package/src/client.ts +41 -51
- package/src/eip191exceptions.ts +2 -2
- package/src/extended.ts +5 -5
- package/src/init.ts +9 -10
- package/src/provider.ts +112 -66
- package/src/signer.ts +38 -43
- package/src/transactions.ts +4 -4
- package/src/transports/base-provider-transport.ts +19 -23
- package/src/transports/base-wallet-transport.ts +22 -13
- package/src/transports/mux-transport/mux-message-provider.ts +5 -6
- package/src/transports/proxy-transport/proxy-message-provider.ts +5 -2
- package/src/transports/unreal-transport/unreal-message-handler.ts +2 -2
- package/src/transports/unreal-transport/unreal-message-provider.ts +2 -2
- package/src/transports/wallet-request-handler.ts +91 -130
- package/src/transports/window-transport/window-message-handler.ts +5 -4
- package/src/transports/window-transport/window-message-provider.ts +4 -4
- package/src/types.ts +8 -11
- package/src/utils/index.ts +4 -4
- package/src/utils.ts +16 -18
|
@@ -17,10 +17,10 @@ import {
|
|
|
17
17
|
TypedEventEmitter
|
|
18
18
|
} from '../types'
|
|
19
19
|
|
|
20
|
-
import { NetworkConfig
|
|
20
|
+
import { NetworkConfig } from '@0xsequence/network'
|
|
21
21
|
import { logger } from '@0xsequence/utils'
|
|
22
22
|
import { ethers } from 'ethers'
|
|
23
|
-
import { commons } from '@0xsequence/core'
|
|
23
|
+
import { VERSION, commons } from '@0xsequence/core'
|
|
24
24
|
|
|
25
25
|
export const PROVIDER_OPEN_TIMEOUT = 30000 // in ms
|
|
26
26
|
|
|
@@ -89,9 +89,7 @@ export abstract class BaseProviderTransport implements ProviderTransport {
|
|
|
89
89
|
)
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
|
|
93
|
-
// here, we receive the message from the dapp provider call
|
|
94
|
-
|
|
92
|
+
async request(request: { method: string; params?: any[]; chainId?: number }): Promise<any> {
|
|
95
93
|
if (this.state === OpenState.CLOSED) {
|
|
96
94
|
// flag the wallet to auto-close once user submits input. ie.
|
|
97
95
|
// prompting to sign a message or transaction
|
|
@@ -104,24 +102,21 @@ export abstract class BaseProviderTransport implements ProviderTransport {
|
|
|
104
102
|
// NOTE: if we're not signed in, then the provider will fail, users must first connect+sign in.
|
|
105
103
|
//
|
|
106
104
|
// TODO: how does this behave with a session has expired?
|
|
107
|
-
this.openWallet(undefined, { type: 'jsonRpcRequest', method: request.method }, chainId)
|
|
105
|
+
this.openWallet(undefined, { type: 'jsonRpcRequest', method: request.method }, request.chainId)
|
|
108
106
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if (!this.isOpened()) {
|
|
112
|
-
await this.waitUntilOpened() // will throw on timeout
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const response = await this.sendMessageRequest({
|
|
116
|
-
idx: nextMessageIdx(),
|
|
117
|
-
type: EventType.MESSAGE,
|
|
118
|
-
data: request,
|
|
119
|
-
chainId: chainId
|
|
120
|
-
})
|
|
121
|
-
callback(undefined, response.data)
|
|
122
|
-
} catch (err) {
|
|
123
|
-
callback(err)
|
|
107
|
+
if (!this.isOpened()) {
|
|
108
|
+
await this.waitUntilOpened() // will throw on timeout
|
|
124
109
|
}
|
|
110
|
+
|
|
111
|
+
const response = await this.sendMessageRequest({
|
|
112
|
+
idx: nextMessageIdx(),
|
|
113
|
+
type: EventType.MESSAGE,
|
|
114
|
+
data: request,
|
|
115
|
+
chainId: request.chainId,
|
|
116
|
+
clientVersion: VERSION
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
return response.data
|
|
125
120
|
}
|
|
126
121
|
|
|
127
122
|
// handleMessage will handle message received from the remote wallet
|
|
@@ -142,7 +137,8 @@ export abstract class BaseProviderTransport implements ProviderTransport {
|
|
|
142
137
|
data: {
|
|
143
138
|
sessionId: this._sessionId,
|
|
144
139
|
nonce: nonce
|
|
145
|
-
}
|
|
140
|
+
},
|
|
141
|
+
clientVersion: VERSION
|
|
146
142
|
})
|
|
147
143
|
}
|
|
148
144
|
|
|
@@ -228,7 +224,7 @@ export abstract class BaseProviderTransport implements ProviderTransport {
|
|
|
228
224
|
this.accountsChangedPayload = { accounts: [] }
|
|
229
225
|
if (message.data && message.data.length > 0) {
|
|
230
226
|
this.accountsChangedPayload = {
|
|
231
|
-
accounts: [ethers.
|
|
227
|
+
accounts: [ethers.getAddress(message.data[0])],
|
|
232
228
|
origin: message.origin
|
|
233
229
|
}
|
|
234
230
|
this.events.emit('accountsChanged', this.accountsChangedPayload.accounts, this.accountsChangedPayload.origin)
|
|
@@ -14,13 +14,13 @@ import {
|
|
|
14
14
|
|
|
15
15
|
import { WalletRequestHandler } from './wallet-request-handler'
|
|
16
16
|
|
|
17
|
-
import { NetworkConfig,
|
|
17
|
+
import { NetworkConfig, findSupportedNetwork } from '@0xsequence/network'
|
|
18
18
|
import { logger, sanitizeAlphanumeric, sanitizeHost, sanitizeNumberString } from '@0xsequence/utils'
|
|
19
19
|
import { AuthorizationOptions } from '@0xsequence/auth'
|
|
20
20
|
|
|
21
21
|
import { PROVIDER_OPEN_TIMEOUT } from './base-provider-transport'
|
|
22
22
|
import { isBrowserExtension, useBestStore } from '../utils'
|
|
23
|
-
import { commons } from '@0xsequence/core'
|
|
23
|
+
import { VERSION, commons } from '@0xsequence/core'
|
|
24
24
|
|
|
25
25
|
const TRANSPORT_SESSION_LS_KEY = '@sequence.transportSession'
|
|
26
26
|
|
|
@@ -65,7 +65,7 @@ export abstract class BaseWalletTransport implements WalletTransport {
|
|
|
65
65
|
if (!networks || networks.length === 0) {
|
|
66
66
|
this.notifyChainChanged('0x0')
|
|
67
67
|
} else {
|
|
68
|
-
this.notifyChainChanged(ethers.
|
|
68
|
+
this.notifyChainChanged(ethers.toQuantity(networks.find(network => network.isDefaultChain)!.chainId))
|
|
69
69
|
}
|
|
70
70
|
})
|
|
71
71
|
|
|
@@ -96,7 +96,7 @@ export abstract class BaseWalletTransport implements WalletTransport {
|
|
|
96
96
|
throw new Error('abstract method')
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
|
|
99
|
+
request(request: { method: string; params?: any[]; chainId?: number }): Promise<any> {
|
|
100
100
|
throw new Error('abstract method')
|
|
101
101
|
}
|
|
102
102
|
|
|
@@ -181,7 +181,8 @@ export abstract class BaseWalletTransport implements WalletTransport {
|
|
|
181
181
|
sessionId,
|
|
182
182
|
session,
|
|
183
183
|
error
|
|
184
|
-
}
|
|
184
|
+
},
|
|
185
|
+
clientVersion: VERSION
|
|
185
186
|
})
|
|
186
187
|
}
|
|
187
188
|
|
|
@@ -189,7 +190,8 @@ export abstract class BaseWalletTransport implements WalletTransport {
|
|
|
189
190
|
this.sendMessage({
|
|
190
191
|
idx: -1,
|
|
191
192
|
type: EventType.CLOSE,
|
|
192
|
-
data: error ? { error } : null
|
|
193
|
+
data: error ? { error } : null,
|
|
194
|
+
clientVersion: VERSION
|
|
193
195
|
})
|
|
194
196
|
}
|
|
195
197
|
|
|
@@ -197,7 +199,8 @@ export abstract class BaseWalletTransport implements WalletTransport {
|
|
|
197
199
|
this.sendMessage({
|
|
198
200
|
idx: -1,
|
|
199
201
|
type: EventType.CONNECT,
|
|
200
|
-
data: connectDetails
|
|
202
|
+
data: connectDetails,
|
|
203
|
+
clientVersion: VERSION
|
|
201
204
|
})
|
|
202
205
|
}
|
|
203
206
|
|
|
@@ -206,7 +209,8 @@ export abstract class BaseWalletTransport implements WalletTransport {
|
|
|
206
209
|
idx: -1,
|
|
207
210
|
type: EventType.DISCONNECT,
|
|
208
211
|
data: error ? { error } : null,
|
|
209
|
-
origin
|
|
212
|
+
origin,
|
|
213
|
+
clientVersion: VERSION
|
|
210
214
|
})
|
|
211
215
|
}
|
|
212
216
|
|
|
@@ -215,7 +219,8 @@ export abstract class BaseWalletTransport implements WalletTransport {
|
|
|
215
219
|
idx: -1,
|
|
216
220
|
type: EventType.ACCOUNTS_CHANGED,
|
|
217
221
|
data: accounts,
|
|
218
|
-
origin
|
|
222
|
+
origin,
|
|
223
|
+
clientVersion: VERSION
|
|
219
224
|
})
|
|
220
225
|
}
|
|
221
226
|
|
|
@@ -224,7 +229,8 @@ export abstract class BaseWalletTransport implements WalletTransport {
|
|
|
224
229
|
idx: -1,
|
|
225
230
|
type: EventType.CHAIN_CHANGED,
|
|
226
231
|
data: chainIdHex,
|
|
227
|
-
origin
|
|
232
|
+
origin,
|
|
233
|
+
clientVersion: VERSION
|
|
228
234
|
})
|
|
229
235
|
}
|
|
230
236
|
|
|
@@ -232,7 +238,8 @@ export abstract class BaseWalletTransport implements WalletTransport {
|
|
|
232
238
|
this.sendMessage({
|
|
233
239
|
idx: -1,
|
|
234
240
|
type: EventType.NETWORKS,
|
|
235
|
-
data: networks
|
|
241
|
+
data: networks,
|
|
242
|
+
clientVersion: VERSION
|
|
236
243
|
})
|
|
237
244
|
}
|
|
238
245
|
|
|
@@ -240,7 +247,8 @@ export abstract class BaseWalletTransport implements WalletTransport {
|
|
|
240
247
|
this.sendMessage({
|
|
241
248
|
idx: -1,
|
|
242
249
|
type: EventType.WALLET_CONTEXT,
|
|
243
|
-
data: walletContext
|
|
250
|
+
data: walletContext,
|
|
251
|
+
clientVersion: VERSION
|
|
244
252
|
})
|
|
245
253
|
}
|
|
246
254
|
|
|
@@ -309,7 +317,8 @@ export abstract class BaseWalletTransport implements WalletTransport {
|
|
|
309
317
|
this.sendMessage({
|
|
310
318
|
idx: -1,
|
|
311
319
|
type: EventType.INIT,
|
|
312
|
-
data: { nonce: this._initNonce }
|
|
320
|
+
data: { nonce: this._initNonce },
|
|
321
|
+
clientVersion: VERSION
|
|
313
322
|
})
|
|
314
323
|
this._init = InitState.SENT_NONCE
|
|
315
324
|
|
|
@@ -9,12 +9,12 @@ import {
|
|
|
9
9
|
ConnectDetails
|
|
10
10
|
} from '../../types'
|
|
11
11
|
|
|
12
|
-
import { JsonRpcRequest, JsonRpcResponseCallback } from '@0xsequence/network'
|
|
13
12
|
import { ProxyMessageChannelPort, ProxyMessageProvider } from '../proxy-transport'
|
|
14
13
|
import { Runtime } from 'webextension-polyfill'
|
|
15
14
|
import { UnrealMessageProvider } from '../unreal-transport'
|
|
16
15
|
import { ExtensionMessageProvider } from '../extension-transport'
|
|
17
16
|
import { WindowMessageProvider } from '../window-transport'
|
|
17
|
+
import { JsonRpcResponse } from '@0xsequence/network'
|
|
18
18
|
|
|
19
19
|
export type MuxTransportTemplate = {
|
|
20
20
|
walletAppURL?: string
|
|
@@ -198,12 +198,11 @@ export class MuxMessageProvider implements ProviderTransport {
|
|
|
198
198
|
return true
|
|
199
199
|
}
|
|
200
200
|
|
|
201
|
-
|
|
202
|
-
if (this.provider) {
|
|
203
|
-
|
|
204
|
-
return
|
|
201
|
+
request(request: { method: string; params?: any[]; chainId?: number }): Promise<any> {
|
|
202
|
+
if (!this.provider) {
|
|
203
|
+
throw new Error('impossible state, wallet must be opened first')
|
|
205
204
|
}
|
|
206
|
-
|
|
205
|
+
return this.provider.request(request)
|
|
207
206
|
}
|
|
208
207
|
|
|
209
208
|
sendMessage(message: ProviderMessage<any>) {
|
|
@@ -3,6 +3,7 @@ import { BaseProviderTransport } from '../base-provider-transport'
|
|
|
3
3
|
import { ProviderMessage, OpenState, OpenWalletIntent, EventType, InitState } from '../../types'
|
|
4
4
|
|
|
5
5
|
import { ProxyMessageChannelPort, ProxyEventTypes } from './proxy-message-channel'
|
|
6
|
+
import { VERSION } from '@0xsequence/core'
|
|
6
7
|
|
|
7
8
|
export class ProxyMessageProvider extends BaseProviderTransport {
|
|
8
9
|
private port: ProxyMessageChannelPort
|
|
@@ -62,7 +63,8 @@ export class ProxyMessageProvider extends BaseProviderTransport {
|
|
|
62
63
|
intent,
|
|
63
64
|
networkId,
|
|
64
65
|
sessionId
|
|
65
|
-
}
|
|
66
|
+
},
|
|
67
|
+
clientVersion: VERSION
|
|
66
68
|
})
|
|
67
69
|
}
|
|
68
70
|
}
|
|
@@ -71,7 +73,8 @@ export class ProxyMessageProvider extends BaseProviderTransport {
|
|
|
71
73
|
this.sendMessage({
|
|
72
74
|
idx: -1,
|
|
73
75
|
type: EventType.CLOSE,
|
|
74
|
-
data: null
|
|
76
|
+
data: null,
|
|
77
|
+
clientVersion: VERSION
|
|
75
78
|
})
|
|
76
79
|
this.close()
|
|
77
80
|
}
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
} from '../../types'
|
|
11
11
|
import { WalletRequestHandler } from '../wallet-request-handler'
|
|
12
12
|
import { BaseWalletTransport } from '../base-wallet-transport'
|
|
13
|
-
import { logger, base64DecodeObject } from '@0xsequence/utils'
|
|
13
|
+
import { logger, base64DecodeObject, bigintReplacer } from '@0xsequence/utils'
|
|
14
14
|
import { overrideLogs } from './overridelogs'
|
|
15
15
|
|
|
16
16
|
// all lowercase is an annoying limitation of Unreal CEF BindUObject
|
|
@@ -104,7 +104,7 @@ export class UnrealMessageHandler extends BaseWalletTransport {
|
|
|
104
104
|
return
|
|
105
105
|
}
|
|
106
106
|
// prepare payload
|
|
107
|
-
const payload = JSON.stringify(message)
|
|
107
|
+
const payload = JSON.stringify(message, bigintReplacer)
|
|
108
108
|
|
|
109
109
|
// post-message to app.
|
|
110
110
|
window.ue?.sequencewallettransport?.sendmessagetosequencejs(payload)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { OpenWalletIntent, ProviderMessage, InitState, WindowSessionParams } from '../../types'
|
|
2
2
|
import { BaseProviderTransport } from '../base-provider-transport'
|
|
3
|
-
import { base64EncodeObject } from '@0xsequence/utils'
|
|
3
|
+
import { base64EncodeObject, bigintReplacer } from '@0xsequence/utils'
|
|
4
4
|
import { overrideLogs } from './overridelogs'
|
|
5
5
|
|
|
6
6
|
let registeredUnrealMessageProvider: UnrealMessageProvider | undefined
|
|
@@ -114,7 +114,7 @@ export class UnrealMessageProvider extends BaseProviderTransport {
|
|
|
114
114
|
|
|
115
115
|
// all lowercase is an annoying limitation of Unreal CEF BindUObject
|
|
116
116
|
sendMessage(message: ProviderMessage<unknown>) {
|
|
117
|
-
const postedMessage = typeof message !== 'string' ? JSON.stringify(message) : message
|
|
117
|
+
const postedMessage = typeof message !== 'string' ? JSON.stringify(message, bigintReplacer) : message
|
|
118
118
|
console.log('Sending message to wallet:', postedMessage)
|
|
119
119
|
window.ue?.sequencewallettransport?.sendmessagetowallet(postedMessage)
|
|
120
120
|
}
|