@0xsequence/provider 0.0.0-20230726163002 → 0.0.0-20230726184000
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 +15 -3
- package/dist/0xsequence-provider.cjs.prod.js +15 -3
- package/dist/0xsequence-provider.esm.js +15 -3
- package/dist/declarations/src/provider.d.ts +6 -2
- package/dist/declarations/src/types.d.ts +6 -0
- package/package.json +10 -10
- package/src/provider.ts +6 -2
- package/src/types.ts +5 -0
- package/src/utils.ts +10 -2
|
@@ -79,6 +79,8 @@ const ErrSignedInRequired = new ProviderError('Wallet is not signed in. Connect
|
|
|
79
79
|
|
|
80
80
|
// TODO: lets build some nice error handling tools, prob in /utils ...
|
|
81
81
|
|
|
82
|
+
// This is required by viem, it expects a provider to have an EIP-1193 compliant `request` attribute.
|
|
83
|
+
|
|
82
84
|
const PROVIDER_OPEN_TIMEOUT = 30000; // in ms
|
|
83
85
|
|
|
84
86
|
let _messageIdx = 0;
|
|
@@ -652,11 +654,10 @@ class LocalStorage {
|
|
|
652
654
|
}
|
|
653
655
|
window.addEventListener('storage', e => {
|
|
654
656
|
const {
|
|
655
|
-
key
|
|
656
|
-
newValue
|
|
657
|
+
key
|
|
657
658
|
} = e;
|
|
658
659
|
const cb = this.callbacks.filter(c => c.key === key);
|
|
659
|
-
cb.forEach(c => c.cb(
|
|
660
|
+
cb.forEach(c => c.cb(this.getItem(key)));
|
|
660
661
|
});
|
|
661
662
|
}
|
|
662
663
|
getItem(key) {
|
|
@@ -664,9 +665,17 @@ class LocalStorage {
|
|
|
664
665
|
}
|
|
665
666
|
setItem(key, value) {
|
|
666
667
|
window.localStorage.setItem(key, value);
|
|
668
|
+
|
|
669
|
+
// Trigger callbacks
|
|
670
|
+
// NOTICE: the event is not triggered on the same window
|
|
671
|
+
this.callbacks.filter(c => c.key === key).forEach(c => c.cb(value));
|
|
667
672
|
}
|
|
668
673
|
removeItem(key) {
|
|
669
674
|
window.localStorage.removeItem(key);
|
|
675
|
+
|
|
676
|
+
// Trigger callbacks
|
|
677
|
+
// NOTICE: the event is not triggered on the same window
|
|
678
|
+
this.callbacks.filter(c => c.key === key).forEach(c => c.cb(null));
|
|
670
679
|
}
|
|
671
680
|
onItemChange(key, cb) {
|
|
672
681
|
this.callbacks.push({
|
|
@@ -3264,6 +3273,9 @@ class SequenceProvider extends ethers.ethers.providers.BaseProvider {
|
|
|
3264
3273
|
send(method, params) {
|
|
3265
3274
|
return this.perform(method, params);
|
|
3266
3275
|
}
|
|
3276
|
+
request(request) {
|
|
3277
|
+
return this.perform(request.method, request.params);
|
|
3278
|
+
}
|
|
3267
3279
|
async detectNetwork() {
|
|
3268
3280
|
const chainId = this.client.getChainId();
|
|
3269
3281
|
const network$1 = network.findNetworkConfig(this.networks, chainId);
|
|
@@ -79,6 +79,8 @@ const ErrSignedInRequired = new ProviderError('Wallet is not signed in. Connect
|
|
|
79
79
|
|
|
80
80
|
// TODO: lets build some nice error handling tools, prob in /utils ...
|
|
81
81
|
|
|
82
|
+
// This is required by viem, it expects a provider to have an EIP-1193 compliant `request` attribute.
|
|
83
|
+
|
|
82
84
|
const PROVIDER_OPEN_TIMEOUT = 30000; // in ms
|
|
83
85
|
|
|
84
86
|
let _messageIdx = 0;
|
|
@@ -652,11 +654,10 @@ class LocalStorage {
|
|
|
652
654
|
}
|
|
653
655
|
window.addEventListener('storage', e => {
|
|
654
656
|
const {
|
|
655
|
-
key
|
|
656
|
-
newValue
|
|
657
|
+
key
|
|
657
658
|
} = e;
|
|
658
659
|
const cb = this.callbacks.filter(c => c.key === key);
|
|
659
|
-
cb.forEach(c => c.cb(
|
|
660
|
+
cb.forEach(c => c.cb(this.getItem(key)));
|
|
660
661
|
});
|
|
661
662
|
}
|
|
662
663
|
getItem(key) {
|
|
@@ -664,9 +665,17 @@ class LocalStorage {
|
|
|
664
665
|
}
|
|
665
666
|
setItem(key, value) {
|
|
666
667
|
window.localStorage.setItem(key, value);
|
|
668
|
+
|
|
669
|
+
// Trigger callbacks
|
|
670
|
+
// NOTICE: the event is not triggered on the same window
|
|
671
|
+
this.callbacks.filter(c => c.key === key).forEach(c => c.cb(value));
|
|
667
672
|
}
|
|
668
673
|
removeItem(key) {
|
|
669
674
|
window.localStorage.removeItem(key);
|
|
675
|
+
|
|
676
|
+
// Trigger callbacks
|
|
677
|
+
// NOTICE: the event is not triggered on the same window
|
|
678
|
+
this.callbacks.filter(c => c.key === key).forEach(c => c.cb(null));
|
|
670
679
|
}
|
|
671
680
|
onItemChange(key, cb) {
|
|
672
681
|
this.callbacks.push({
|
|
@@ -3264,6 +3273,9 @@ class SequenceProvider extends ethers.ethers.providers.BaseProvider {
|
|
|
3264
3273
|
send(method, params) {
|
|
3265
3274
|
return this.perform(method, params);
|
|
3266
3275
|
}
|
|
3276
|
+
request(request) {
|
|
3277
|
+
return this.perform(request.method, request.params);
|
|
3278
|
+
}
|
|
3267
3279
|
async detectNetwork() {
|
|
3268
3280
|
const chainId = this.client.getChainId();
|
|
3269
3281
|
const network$1 = network.findNetworkConfig(this.networks, chainId);
|
|
@@ -75,6 +75,8 @@ const ErrSignedInRequired = new ProviderError('Wallet is not signed in. Connect
|
|
|
75
75
|
|
|
76
76
|
// TODO: lets build some nice error handling tools, prob in /utils ...
|
|
77
77
|
|
|
78
|
+
// This is required by viem, it expects a provider to have an EIP-1193 compliant `request` attribute.
|
|
79
|
+
|
|
78
80
|
const PROVIDER_OPEN_TIMEOUT = 30000; // in ms
|
|
79
81
|
|
|
80
82
|
let _messageIdx = 0;
|
|
@@ -648,11 +650,10 @@ class LocalStorage {
|
|
|
648
650
|
}
|
|
649
651
|
window.addEventListener('storage', e => {
|
|
650
652
|
const {
|
|
651
|
-
key
|
|
652
|
-
newValue
|
|
653
|
+
key
|
|
653
654
|
} = e;
|
|
654
655
|
const cb = this.callbacks.filter(c => c.key === key);
|
|
655
|
-
cb.forEach(c => c.cb(
|
|
656
|
+
cb.forEach(c => c.cb(this.getItem(key)));
|
|
656
657
|
});
|
|
657
658
|
}
|
|
658
659
|
getItem(key) {
|
|
@@ -660,9 +661,17 @@ class LocalStorage {
|
|
|
660
661
|
}
|
|
661
662
|
setItem(key, value) {
|
|
662
663
|
window.localStorage.setItem(key, value);
|
|
664
|
+
|
|
665
|
+
// Trigger callbacks
|
|
666
|
+
// NOTICE: the event is not triggered on the same window
|
|
667
|
+
this.callbacks.filter(c => c.key === key).forEach(c => c.cb(value));
|
|
663
668
|
}
|
|
664
669
|
removeItem(key) {
|
|
665
670
|
window.localStorage.removeItem(key);
|
|
671
|
+
|
|
672
|
+
// Trigger callbacks
|
|
673
|
+
// NOTICE: the event is not triggered on the same window
|
|
674
|
+
this.callbacks.filter(c => c.key === key).forEach(c => c.cb(null));
|
|
666
675
|
}
|
|
667
676
|
onItemChange(key, cb) {
|
|
668
677
|
this.callbacks.push({
|
|
@@ -3260,6 +3269,9 @@ class SequenceProvider extends ethers.providers.BaseProvider {
|
|
|
3260
3269
|
send(method, params) {
|
|
3261
3270
|
return this.perform(method, params);
|
|
3262
3271
|
}
|
|
3272
|
+
request(request) {
|
|
3273
|
+
return this.perform(request.method, request.params);
|
|
3274
|
+
}
|
|
3263
3275
|
async detectNetwork() {
|
|
3264
3276
|
const chainId = this.client.getChainId();
|
|
3265
3277
|
const network = findNetworkConfig(this.networks, chainId);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ethers } from "ethers";
|
|
2
2
|
import { SequenceClient } from "./client.js";
|
|
3
3
|
import { ChainIdLike, NetworkConfig } from "@0xsequence/network";
|
|
4
|
-
import { ConnectDetails, ConnectOptions, OpenWalletIntent, OptionalChainIdLike, WalletSession } from "./types.js";
|
|
4
|
+
import { ConnectDetails, ConnectOptions, EIP1193Provider, OpenWalletIntent, OptionalChainIdLike, WalletSession } from "./types.js";
|
|
5
5
|
import { commons } from "@0xsequence/core";
|
|
6
6
|
import { WalletUtils } from "./utils/index.js";
|
|
7
7
|
import { SequenceSigner, SingleNetworkSequenceSigner } from "./signer.js";
|
|
@@ -29,7 +29,7 @@ export interface ISequenceProvider {
|
|
|
29
29
|
getWalletConfig(chainId?: ChainIdLike): Promise<commons.config.Config>;
|
|
30
30
|
utils: WalletUtils;
|
|
31
31
|
}
|
|
32
|
-
export declare class SequenceProvider extends ethers.providers.BaseProvider implements ISequenceProvider {
|
|
32
|
+
export declare class SequenceProvider extends ethers.providers.BaseProvider implements ISequenceProvider, EIP1193Provider {
|
|
33
33
|
readonly client: SequenceClient;
|
|
34
34
|
private readonly providerFor;
|
|
35
35
|
readonly networks: NetworkConfig[];
|
|
@@ -79,6 +79,10 @@ export declare class SequenceProvider extends ethers.providers.BaseProvider impl
|
|
|
79
79
|
_getSubprovider(chainId?: ChainIdLike): Promise<ethers.providers.JsonRpcProvider>;
|
|
80
80
|
perform(method: string, params: any): Promise<any>;
|
|
81
81
|
send(method: string, params: any): Promise<any>;
|
|
82
|
+
request(request: {
|
|
83
|
+
method: string;
|
|
84
|
+
params?: any[] | undefined;
|
|
85
|
+
}): Promise<any>;
|
|
82
86
|
detectNetwork(): Promise<ethers.providers.Network>;
|
|
83
87
|
waitForTransaction(transactionHash: string, confirmations?: number, timeout?: number, optionals?: OptionalChainIdLike): Promise<ethers.providers.TransactionReceipt>;
|
|
84
88
|
getBlockNumber(optionals?: OptionalChainIdLike): Promise<number>;
|
|
@@ -244,4 +244,10 @@ export type OptionalChainId = {
|
|
|
244
244
|
export type OptionalEIP6492 = {
|
|
245
245
|
eip6492?: boolean;
|
|
246
246
|
} | undefined;
|
|
247
|
+
export interface EIP1193Provider {
|
|
248
|
+
request: (request: {
|
|
249
|
+
method: string;
|
|
250
|
+
params?: Array<any>;
|
|
251
|
+
}) => Promise<any>;
|
|
252
|
+
}
|
|
247
253
|
export {};
|
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-20230726184000",
|
|
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",
|
|
@@ -11,15 +11,15 @@
|
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"eventemitter2": "^6.4.5",
|
|
13
13
|
"webextension-polyfill": "^0.10.0",
|
|
14
|
-
"@0xsequence/
|
|
15
|
-
"@0xsequence/
|
|
16
|
-
"@0xsequence/
|
|
17
|
-
"@0xsequence/
|
|
18
|
-
"@0xsequence/network": "0.0.0-
|
|
19
|
-
"@0xsequence/
|
|
20
|
-
"@0xsequence/
|
|
21
|
-
"@0xsequence/
|
|
22
|
-
"@0xsequence/
|
|
14
|
+
"@0xsequence/account": "0.0.0-20230726184000",
|
|
15
|
+
"@0xsequence/core": "0.0.0-20230726184000",
|
|
16
|
+
"@0xsequence/auth": "0.0.0-20230726184000",
|
|
17
|
+
"@0xsequence/abi": "0.0.0-20230726184000",
|
|
18
|
+
"@0xsequence/network": "0.0.0-20230726184000",
|
|
19
|
+
"@0xsequence/migration": "0.0.0-20230726184000",
|
|
20
|
+
"@0xsequence/relayer": "0.0.0-20230726184000",
|
|
21
|
+
"@0xsequence/utils": "0.0.0-20230726184000",
|
|
22
|
+
"@0xsequence/wallet": "0.0.0-20230726184000"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"ethers": ">=5.5 < 6"
|
package/src/provider.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { ethers } from "ethers"
|
|
3
3
|
import { SequenceClient } from "./client"
|
|
4
4
|
import { ChainIdLike, NetworkConfig, allNetworks, findNetworkConfig } from "@0xsequence/network"
|
|
5
|
-
import { ConnectDetails, ConnectOptions, OpenWalletIntent, OptionalChainIdLike, WalletSession } from "./types"
|
|
5
|
+
import { ConnectDetails, ConnectOptions, EIP1193Provider, OpenWalletIntent, OptionalChainIdLike, WalletSession } from "./types"
|
|
6
6
|
import { commons } from "@0xsequence/core"
|
|
7
7
|
import { WalletUtils } from "./utils/index"
|
|
8
8
|
import { SequenceSigner, SingleNetworkSequenceSigner } from "./signer"
|
|
@@ -47,7 +47,7 @@ export interface ISequenceProvider {
|
|
|
47
47
|
utils: WalletUtils
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
export class SequenceProvider extends ethers.providers.BaseProvider implements ISequenceProvider {
|
|
50
|
+
export class SequenceProvider extends ethers.providers.BaseProvider implements ISequenceProvider, EIP1193Provider {
|
|
51
51
|
private readonly singleNetworkProviders: { [chainId: number]: SingleNetworkSequenceProvider } = {}
|
|
52
52
|
|
|
53
53
|
readonly _isSequenceProvider = true
|
|
@@ -269,6 +269,10 @@ export class SequenceProvider extends ethers.providers.BaseProvider implements I
|
|
|
269
269
|
return this.perform(method, params)
|
|
270
270
|
}
|
|
271
271
|
|
|
272
|
+
request (request: { method: string; params?: any[] | undefined }) {
|
|
273
|
+
return this.perform(request.method, request.params)
|
|
274
|
+
}
|
|
275
|
+
|
|
272
276
|
async detectNetwork(): Promise<ethers.providers.Network> {
|
|
273
277
|
const chainId = this.client.getChainId()
|
|
274
278
|
const network = findNetworkConfig(this.networks, chainId)
|
package/src/types.ts
CHANGED
|
@@ -340,3 +340,8 @@ export type OptionalChainId = {
|
|
|
340
340
|
export type OptionalEIP6492 = {
|
|
341
341
|
eip6492?: boolean
|
|
342
342
|
} | undefined
|
|
343
|
+
|
|
344
|
+
// This is required by viem, it expects a provider to have an EIP-1193 compliant `request` attribute.
|
|
345
|
+
export interface EIP1193Provider {
|
|
346
|
+
request: (request: { method: string, params?: Array<any> }) => Promise<any>
|
|
347
|
+
}
|
package/src/utils.ts
CHANGED
|
@@ -158,9 +158,9 @@ export class LocalStorage implements ItemStore {
|
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
window.addEventListener('storage', (e) => {
|
|
161
|
-
const { key
|
|
161
|
+
const { key } = e
|
|
162
162
|
const cb = this.callbacks.filter((c) => c.key === key)
|
|
163
|
-
cb.forEach((c) => c.cb(
|
|
163
|
+
cb.forEach((c) => c.cb(this.getItem(key!)))
|
|
164
164
|
})
|
|
165
165
|
}
|
|
166
166
|
|
|
@@ -170,10 +170,18 @@ export class LocalStorage implements ItemStore {
|
|
|
170
170
|
|
|
171
171
|
setItem(key: string, value: string): void {
|
|
172
172
|
window.localStorage.setItem(key, value)
|
|
173
|
+
|
|
174
|
+
// Trigger callbacks
|
|
175
|
+
// NOTICE: the event is not triggered on the same window
|
|
176
|
+
this.callbacks.filter((c) => c.key === key).forEach((c) => c.cb(value))
|
|
173
177
|
}
|
|
174
178
|
|
|
175
179
|
removeItem(key: string): void {
|
|
176
180
|
window.localStorage.removeItem(key)
|
|
181
|
+
|
|
182
|
+
// Trigger callbacks
|
|
183
|
+
// NOTICE: the event is not triggered on the same window
|
|
184
|
+
this.callbacks.filter((c) => c.key === key).forEach((c) => c.cb(null))
|
|
177
185
|
}
|
|
178
186
|
|
|
179
187
|
onItemChange(key: string, cb: (value: string | null) => void): () => void {
|