@0xsequence/provider 0.36.7 → 0.36.8
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 +1 -1
- package/dist/0xsequence-provider.cjs.prod.js +1 -1
- package/dist/0xsequence-provider.esm.js +1 -1
- package/dist/declarations/src/types.d.ts +58 -10
- package/package.json +8 -8
- package/src/transports/window-transport/window-message-provider.ts +4 -7
- package/src/types.ts +83 -44
|
@@ -2692,7 +2692,7 @@ class WindowMessageProvider extends BaseProviderTransport {
|
|
|
2692
2692
|
if (!isBrowserExtension()) {
|
|
2693
2693
|
intent.options.origin = window.location.origin;
|
|
2694
2694
|
}
|
|
2695
|
-
} // encode intent as
|
|
2695
|
+
} // encode intent as base64 url-encoded param
|
|
2696
2696
|
|
|
2697
2697
|
|
|
2698
2698
|
windowSessionParams.set('intent', utils.base64EncodeObject(intent));
|
|
@@ -2692,7 +2692,7 @@ class WindowMessageProvider extends BaseProviderTransport {
|
|
|
2692
2692
|
if (!isBrowserExtension()) {
|
|
2693
2693
|
intent.options.origin = window.location.origin;
|
|
2694
2694
|
}
|
|
2695
|
-
} // encode intent as
|
|
2695
|
+
} // encode intent as base64 url-encoded param
|
|
2696
2696
|
|
|
2697
2697
|
|
|
2698
2698
|
windowSessionParams.set('intent', utils.base64EncodeObject(intent));
|
|
@@ -2688,7 +2688,7 @@ class WindowMessageProvider extends BaseProviderTransport {
|
|
|
2688
2688
|
if (!isBrowserExtension()) {
|
|
2689
2689
|
intent.options.origin = window.location.origin;
|
|
2690
2690
|
}
|
|
2691
|
-
} // encode intent as
|
|
2691
|
+
} // encode intent as base64 url-encoded param
|
|
2692
2692
|
|
|
2693
2693
|
|
|
2694
2694
|
windowSessionParams.set('intent', base64EncodeObject(intent));
|
|
@@ -78,22 +78,22 @@ export declare enum EventType {
|
|
|
78
78
|
DEBUG = "_debug"
|
|
79
79
|
}
|
|
80
80
|
export interface WalletEventTypes {
|
|
81
|
-
|
|
81
|
+
open: (openInfo: {
|
|
82
82
|
chainId?: string;
|
|
83
83
|
sessionId?: string;
|
|
84
84
|
session?: WalletSession;
|
|
85
85
|
error?: string;
|
|
86
86
|
}) => void;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
87
|
+
close: (error?: ProviderRpcError) => void;
|
|
88
|
+
connect: (connectDetails: ConnectDetails) => void;
|
|
89
|
+
disconnect: (error?: ProviderRpcError) => void;
|
|
90
|
+
accountsChanged: (accounts: string[]) => void;
|
|
91
|
+
chainChanged: (chainIdHex: string) => void;
|
|
92
|
+
networks: (networks: NetworkConfig[]) => void;
|
|
93
|
+
walletContext: (walletContext: WalletContext) => void;
|
|
94
94
|
}
|
|
95
95
|
export interface ProviderEventTypes extends WalletEventTypes {
|
|
96
|
-
|
|
96
|
+
message: (message: ProviderMessageResponse) => void;
|
|
97
97
|
}
|
|
98
98
|
export declare enum OpenState {
|
|
99
99
|
CLOSED = 0,
|
|
@@ -106,15 +106,60 @@ export declare enum InitState {
|
|
|
106
106
|
OK = 2
|
|
107
107
|
}
|
|
108
108
|
export interface ConnectOptions {
|
|
109
|
+
/** Specifies the default network a dapp would like to connect to. This field
|
|
110
|
+
* is optional as it can be provided a number of different ways. */
|
|
109
111
|
networkId?: string | number;
|
|
112
|
+
/** app name of the dapp which will be announced to user on connect screen */
|
|
110
113
|
app?: string;
|
|
114
|
+
/** origin hint of the dapp's host opening the wallet. This value will automatically
|
|
115
|
+
* be determined and verified for integrity, and can be omitted. */
|
|
111
116
|
origin?: string;
|
|
117
|
+
/** expiry number (in seconds) to expire connect session. default is 1 week of seconds. */
|
|
112
118
|
expiry?: number;
|
|
119
|
+
/** authorize will perform an ETHAuth eip712 signing and return the proof to the dapp. */
|
|
113
120
|
authorize?: boolean;
|
|
121
|
+
/** *Currently not used* askForEmail will prompt to give permission to the dapp to access email address */
|
|
114
122
|
askForEmail?: boolean;
|
|
123
|
+
/** refresh flag will force a full re-connect (ie. disconnect then connect again) */
|
|
115
124
|
refresh?: boolean;
|
|
125
|
+
/** keepWalletOpened will keep the wallet window opened after connecting. The default
|
|
126
|
+
* is to automatically close the wallet after connecting. */
|
|
116
127
|
keepWalletOpened?: boolean;
|
|
117
|
-
|
|
128
|
+
/** Options to further customize the wallet experience. */
|
|
129
|
+
settings?: Settings;
|
|
130
|
+
}
|
|
131
|
+
/** Options to further customize the wallet experience. */
|
|
132
|
+
export interface Settings {
|
|
133
|
+
/** Specify a wallet theme. `light` and `dark` are the main themes, to use other available
|
|
134
|
+
* themes, you can use the camel case version of the theme names in the wallet settings.
|
|
135
|
+
* For example: "Blue Dark" on wallet UI can be passed as "blueDark".
|
|
136
|
+
* Note that this setting will not be persisted, use wallet.open with 'openWithOptions' intent
|
|
137
|
+
* to set when you open the wallet for user. */
|
|
138
|
+
theme?: ThemeOption;
|
|
139
|
+
/** Specify payment providers to use. If not specified,
|
|
140
|
+
* all available payment providers will be enabled.
|
|
141
|
+
* Note that this setting will not be persisted, use wallet.open with 'openWithOptions' intent
|
|
142
|
+
* to set when you open the wallet for user. */
|
|
143
|
+
includedPaymentProviders?: PaymentProviderOption[];
|
|
144
|
+
/** Specify a default currency to use with payment providers.
|
|
145
|
+
* If not specified, the default is USDC.
|
|
146
|
+
* Note that this setting will not be persisted, use wallet.open with 'openWithOptions' intent
|
|
147
|
+
* to set when you open the wallet for user. */
|
|
148
|
+
defaultFundingCurrency?: CurrencyOption;
|
|
149
|
+
/** If true, lockFundingCurrencyToDefault disables picking any currency provided by payment
|
|
150
|
+
* providers other than the defaultFundingCurrency.
|
|
151
|
+
* If false, it allows picking any currency provided by payment providers.
|
|
152
|
+
* The default is true.
|
|
153
|
+
* Note that this setting will not be persisted, use wallet.open with 'openWithOptions' intent
|
|
154
|
+
* to set when you open the wallet for user. */
|
|
155
|
+
lockFundingCurrencyToDefault?: boolean;
|
|
156
|
+
}
|
|
157
|
+
/** light and dark are the main themes, to use other themes in wallet settings,
|
|
158
|
+
* you can use the camel case version of the name in the wallet settings.
|
|
159
|
+
* For example: "Blue Dark" on wallet UI can be passed as "blueDark" */
|
|
160
|
+
export declare type ThemeOption = 'light' | 'dark' | string;
|
|
161
|
+
export declare type PaymentProviderOption = 'moonpay' | 'wyre' | 'ramp';
|
|
162
|
+
export declare type CurrencyOption = 'usdc' | 'eth' | 'matic';
|
|
118
163
|
export interface ConnectDetails {
|
|
119
164
|
chainId?: string;
|
|
120
165
|
error?: string;
|
|
@@ -127,6 +172,9 @@ export declare type PromptConnectDetails = Pick<ConnectDetails, 'chainId' | 'err
|
|
|
127
172
|
export declare type OpenWalletIntent = {
|
|
128
173
|
type: 'connect';
|
|
129
174
|
options?: ConnectOptions;
|
|
175
|
+
} | {
|
|
176
|
+
type: 'openWithOptions';
|
|
177
|
+
options?: ConnectOptions;
|
|
130
178
|
} | {
|
|
131
179
|
type: 'jsonRpcRequest';
|
|
132
180
|
method: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xsequence/provider",
|
|
3
|
-
"version": "0.36.
|
|
3
|
+
"version": "0.36.8",
|
|
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",
|
|
@@ -13,13 +13,13 @@
|
|
|
13
13
|
"typecheck": "tsc --noEmit"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@0xsequence/abi": "^0.36.
|
|
17
|
-
"@0xsequence/auth": "^0.36.
|
|
18
|
-
"@0xsequence/config": "^0.36.
|
|
19
|
-
"@0xsequence/network": "^0.36.
|
|
20
|
-
"@0xsequence/transactions": "^0.36.
|
|
21
|
-
"@0xsequence/utils": "^0.36.
|
|
22
|
-
"@0xsequence/wallet": "^0.36.
|
|
16
|
+
"@0xsequence/abi": "^0.36.8",
|
|
17
|
+
"@0xsequence/auth": "^0.36.8",
|
|
18
|
+
"@0xsequence/config": "^0.36.8",
|
|
19
|
+
"@0xsequence/network": "^0.36.8",
|
|
20
|
+
"@0xsequence/transactions": "^0.36.8",
|
|
21
|
+
"@0xsequence/utils": "^0.36.8",
|
|
22
|
+
"@0xsequence/wallet": "^0.36.8",
|
|
23
23
|
"@ethersproject/abstract-signer": "^5.5.0",
|
|
24
24
|
"@ethersproject/hash": "^5.5.0",
|
|
25
25
|
"@ethersproject/providers": "^5.5.1",
|
|
@@ -82,7 +82,7 @@ export class WindowMessageProvider extends BaseProviderTransport {
|
|
|
82
82
|
this._init = InitState.NIL
|
|
83
83
|
this._sessionId = `${performance.now()}`
|
|
84
84
|
windowSessionParams.set('sid', this._sessionId)
|
|
85
|
-
|
|
85
|
+
|
|
86
86
|
if (intent) {
|
|
87
87
|
// for the window-transport, we eagerly/optimistically set the origin host
|
|
88
88
|
// when connecting to the wallet, however, this will be verified and enforced
|
|
@@ -96,7 +96,7 @@ export class WindowMessageProvider extends BaseProviderTransport {
|
|
|
96
96
|
intent.options.origin = window.location.origin
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
|
-
// encode intent as
|
|
99
|
+
// encode intent as base64 url-encoded param
|
|
100
100
|
windowSessionParams.set('intent', base64EncodeObject(intent))
|
|
101
101
|
}
|
|
102
102
|
if (networkId) {
|
|
@@ -109,16 +109,13 @@ export class WindowMessageProvider extends BaseProviderTransport {
|
|
|
109
109
|
|
|
110
110
|
if (isBrowserExtension()) {
|
|
111
111
|
windowSize = [450, 750]
|
|
112
|
-
windowPos = [
|
|
113
|
-
Math.abs(window.screen.width / 2 - windowSize[0] / 2),
|
|
114
|
-
Math.abs(window.screen.height / 2 - windowSize[1] / 2)
|
|
115
|
-
]
|
|
112
|
+
windowPos = [Math.abs(window.screen.width / 2 - windowSize[0] / 2), Math.abs(window.screen.height / 2 - windowSize[1] / 2)]
|
|
116
113
|
} else {
|
|
117
114
|
windowSize = [450, 750]
|
|
118
115
|
windowPos = [
|
|
119
116
|
Math.abs(window.screenX + window.innerWidth / 2 - windowSize[0] / 2),
|
|
120
117
|
Math.abs(window.screenY + window.innerHeight / 2 - windowSize[1] / 2)
|
|
121
|
-
]
|
|
118
|
+
]
|
|
122
119
|
}
|
|
123
120
|
|
|
124
121
|
const windowFeatures =
|
package/src/types.ts
CHANGED
|
@@ -23,7 +23,7 @@ export interface WalletTransport extends JsonRpcHandler, ProviderMessageTranspor
|
|
|
23
23
|
register(): void
|
|
24
24
|
unregister(): void
|
|
25
25
|
|
|
26
|
-
notifyOpen(openInfo: { chainId?: string
|
|
26
|
+
notifyOpen(openInfo: { chainId?: string; sessionId?: string; session?: WalletSession; error?: string }): void
|
|
27
27
|
notifyClose(error?: ProviderRpcError): void
|
|
28
28
|
|
|
29
29
|
notifyConnect(connectDetails: ConnectDetails): void
|
|
@@ -33,10 +33,10 @@ export interface WalletTransport extends JsonRpcHandler, ProviderMessageTranspor
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
export interface ProviderMessage<T> {
|
|
36
|
-
idx: number
|
|
37
|
-
type: string
|
|
38
|
-
data: T
|
|
39
|
-
chainId?: number
|
|
36
|
+
idx: number // message id number
|
|
37
|
+
type: string // message type
|
|
38
|
+
data: T // the ethereum json-rpc payload
|
|
39
|
+
chainId?: number // chain id which the message is intended
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
export type ProviderMessageRequest = ProviderMessage<JsonRpcRequest>
|
|
@@ -83,8 +83,8 @@ export class WindowSessionParams extends URLSearchParams {
|
|
|
83
83
|
|
|
84
84
|
export interface TransportSession {
|
|
85
85
|
sessionId?: string | null
|
|
86
|
-
networkId?: string | number | null
|
|
87
|
-
intent?: OpenWalletIntent
|
|
86
|
+
networkId?: string | number | null
|
|
87
|
+
intent?: OpenWalletIntent
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
export enum EventType {
|
|
@@ -105,21 +105,21 @@ export enum EventType {
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
export interface WalletEventTypes {
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
open: (openInfo: { chainId?: string; sessionId?: string; session?: WalletSession; error?: string }) => void
|
|
109
|
+
close: (error?: ProviderRpcError) => void
|
|
110
110
|
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
connect: (connectDetails: ConnectDetails) => void
|
|
112
|
+
disconnect: (error?: ProviderRpcError) => void
|
|
113
113
|
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
accountsChanged: (accounts: string[]) => void
|
|
115
|
+
chainChanged: (chainIdHex: string) => void
|
|
116
116
|
|
|
117
|
-
|
|
118
|
-
|
|
117
|
+
networks: (networks: NetworkConfig[]) => void
|
|
118
|
+
walletContext: (walletContext: WalletContext) => void
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
export interface ProviderEventTypes extends WalletEventTypes {
|
|
122
|
-
|
|
122
|
+
message: (message: ProviderMessageResponse) => void
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
export enum OpenState {
|
|
@@ -135,35 +135,75 @@ export enum InitState {
|
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
export interface ConnectOptions {
|
|
138
|
-
|
|
139
|
-
|
|
138
|
+
/** Specifies the default network a dapp would like to connect to. This field
|
|
139
|
+
* is optional as it can be provided a number of different ways. */
|
|
140
140
|
networkId?: string | number
|
|
141
141
|
|
|
142
|
-
|
|
142
|
+
/** app name of the dapp which will be announced to user on connect screen */
|
|
143
143
|
app?: string
|
|
144
144
|
|
|
145
|
-
|
|
146
|
-
|
|
145
|
+
/** origin hint of the dapp's host opening the wallet. This value will automatically
|
|
146
|
+
* be determined and verified for integrity, and can be omitted. */
|
|
147
147
|
origin?: string
|
|
148
148
|
|
|
149
|
-
|
|
149
|
+
/** expiry number (in seconds) to expire connect session. default is 1 week of seconds. */
|
|
150
150
|
expiry?: number
|
|
151
151
|
|
|
152
|
-
|
|
152
|
+
/** authorize will perform an ETHAuth eip712 signing and return the proof to the dapp. */
|
|
153
153
|
authorize?: boolean
|
|
154
154
|
|
|
155
|
-
|
|
155
|
+
/** *Currently not used* askForEmail will prompt to give permission to the dapp to access email address */
|
|
156
156
|
// TODO: this feature is currently not used as the wallet does not report emails yet
|
|
157
157
|
askForEmail?: boolean
|
|
158
158
|
|
|
159
|
-
|
|
159
|
+
/** refresh flag will force a full re-connect (ie. disconnect then connect again) */
|
|
160
160
|
refresh?: boolean
|
|
161
161
|
|
|
162
|
-
|
|
163
|
-
|
|
162
|
+
/** keepWalletOpened will keep the wallet window opened after connecting. The default
|
|
163
|
+
* is to automatically close the wallet after connecting. */
|
|
164
164
|
keepWalletOpened?: boolean
|
|
165
|
+
|
|
166
|
+
/** Options to further customize the wallet experience. */
|
|
167
|
+
settings?: Settings
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** Options to further customize the wallet experience. */
|
|
171
|
+
export interface Settings {
|
|
172
|
+
/** Specify a wallet theme. `light` and `dark` are the main themes, to use other available
|
|
173
|
+
* themes, you can use the camel case version of the theme names in the wallet settings.
|
|
174
|
+
* For example: "Blue Dark" on wallet UI can be passed as "blueDark".
|
|
175
|
+
* Note that this setting will not be persisted, use wallet.open with 'openWithOptions' intent
|
|
176
|
+
* to set when you open the wallet for user. */
|
|
177
|
+
theme?: ThemeOption
|
|
178
|
+
|
|
179
|
+
/** Specify payment providers to use. If not specified,
|
|
180
|
+
* all available payment providers will be enabled.
|
|
181
|
+
* Note that this setting will not be persisted, use wallet.open with 'openWithOptions' intent
|
|
182
|
+
* to set when you open the wallet for user. */
|
|
183
|
+
includedPaymentProviders?: PaymentProviderOption[]
|
|
184
|
+
|
|
185
|
+
/** Specify a default currency to use with payment providers.
|
|
186
|
+
* If not specified, the default is USDC.
|
|
187
|
+
* Note that this setting will not be persisted, use wallet.open with 'openWithOptions' intent
|
|
188
|
+
* to set when you open the wallet for user. */
|
|
189
|
+
defaultFundingCurrency?: CurrencyOption
|
|
190
|
+
|
|
191
|
+
/** If true, lockFundingCurrencyToDefault disables picking any currency provided by payment
|
|
192
|
+
* providers other than the defaultFundingCurrency.
|
|
193
|
+
* If false, it allows picking any currency provided by payment providers.
|
|
194
|
+
* The default is true.
|
|
195
|
+
* Note that this setting will not be persisted, use wallet.open with 'openWithOptions' intent
|
|
196
|
+
* to set when you open the wallet for user. */
|
|
197
|
+
lockFundingCurrencyToDefault?: boolean
|
|
165
198
|
}
|
|
166
199
|
|
|
200
|
+
/** light and dark are the main themes, to use other themes in wallet settings,
|
|
201
|
+
* you can use the camel case version of the name in the wallet settings.
|
|
202
|
+
* For example: "Blue Dark" on wallet UI can be passed as "blueDark" */
|
|
203
|
+
export type ThemeOption = 'light' | 'dark' | string
|
|
204
|
+
export type PaymentProviderOption = 'moonpay' | 'wyre' | 'ramp'
|
|
205
|
+
export type CurrencyOption = 'usdc' | 'eth' | 'matic'
|
|
206
|
+
|
|
167
207
|
export interface ConnectDetails {
|
|
168
208
|
// chainId (in hex) and error are defined by EIP-1193 expected fields
|
|
169
209
|
chainId?: string
|
|
@@ -187,8 +227,9 @@ export interface ConnectDetails {
|
|
|
187
227
|
export type PromptConnectDetails = Pick<ConnectDetails, 'chainId' | 'error' | 'connected' | 'proof' | 'email'>
|
|
188
228
|
|
|
189
229
|
export type OpenWalletIntent =
|
|
190
|
-
{ type: 'connect'; options?: ConnectOptions }
|
|
191
|
-
{ type: '
|
|
230
|
+
| { type: 'connect'; options?: ConnectOptions }
|
|
231
|
+
| { type: 'openWithOptions'; options?: ConnectOptions }
|
|
232
|
+
| { type: 'jsonRpcRequest'; method: string }
|
|
192
233
|
|
|
193
234
|
export interface MessageToSign {
|
|
194
235
|
message?: string
|
|
@@ -230,23 +271,21 @@ export const ErrSignedInRequired = new ProviderError('Wallet is not signed in. C
|
|
|
230
271
|
|
|
231
272
|
// TODO: lets build some nice error handling tools, prob in /utils ...
|
|
232
273
|
|
|
233
|
-
export interface TypedEventEmitter<Events>{
|
|
234
|
-
addListener<E extends keyof Events>
|
|
235
|
-
on<E extends keyof Events>
|
|
236
|
-
once<E extends keyof Events>
|
|
237
|
-
prependListener<E extends keyof Events>
|
|
238
|
-
prependOnceListener<E extends keyof Events>
|
|
274
|
+
export interface TypedEventEmitter<Events> {
|
|
275
|
+
addListener<E extends keyof Events>(event: E, listener: Events[E]): this
|
|
276
|
+
on<E extends keyof Events>(event: E, listener: Events[E]): this
|
|
277
|
+
once<E extends keyof Events>(event: E, listener: Events[E]): this
|
|
278
|
+
prependListener<E extends keyof Events>(event: E, listener: Events[E]): this
|
|
279
|
+
prependOnceListener<E extends keyof Events>(event: E, listener: Events[E]): this
|
|
239
280
|
|
|
240
281
|
off<E extends keyof Events>(event: E, listener: Events[E]): this
|
|
241
|
-
removeAllListeners<E extends keyof Events>
|
|
242
|
-
removeListener<E extends keyof Events>
|
|
282
|
+
removeAllListeners<E extends keyof Events>(event?: E): this
|
|
283
|
+
removeListener<E extends keyof Events>(event: E, listener: Events[E]): this
|
|
243
284
|
|
|
244
|
-
emit<E extends keyof Events>
|
|
245
|
-
eventNames
|
|
246
|
-
listeners<E extends keyof Events>
|
|
247
|
-
listenerCount<E extends keyof Events>
|
|
285
|
+
emit<E extends keyof Events>(event: E, ...args: Arguments<Events[E]>): boolean
|
|
286
|
+
eventNames(): (keyof Events | string | symbol)[]
|
|
287
|
+
listeners<E extends keyof Events>(event: E): Function[]
|
|
288
|
+
listenerCount<E extends keyof Events>(event: E): number
|
|
248
289
|
}
|
|
249
290
|
|
|
250
|
-
type Arguments<T> = [T] extends [(...args: infer U) => any]
|
|
251
|
-
? U
|
|
252
|
-
: [T] extends [void] ? [] : [T]
|
|
291
|
+
type Arguments<T> = [T] extends [(...args: infer U) => any] ? U : [T] extends [void] ? [] : [T]
|