@0xsequence/relayer 1.2.9 → 1.4.0
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.
|
@@ -602,10 +602,41 @@ function isRpcRelayerOptions(obj) {
|
|
|
602
602
|
return obj.url !== undefined && typeof obj.url === 'string' && obj.provider !== undefined && ethers.ethers.providers.Provider.isProvider(obj.provider);
|
|
603
603
|
}
|
|
604
604
|
const fetch = typeof global === 'object' ? global.fetch : window.fetch;
|
|
605
|
+
|
|
606
|
+
// TODO: rename to SequenceRelayer
|
|
605
607
|
class RpcRelayer {
|
|
606
608
|
constructor(options) {
|
|
607
|
-
this.
|
|
608
|
-
|
|
609
|
+
this._fetch = (input, init) => {
|
|
610
|
+
// automatically include jwt and access key auth header to requests
|
|
611
|
+
// if its been set on the api client
|
|
612
|
+
const headers = {};
|
|
613
|
+
const {
|
|
614
|
+
jwtAuth,
|
|
615
|
+
projectAccessKey
|
|
616
|
+
} = this.options;
|
|
617
|
+
if (jwtAuth && jwtAuth.length > 0) {
|
|
618
|
+
headers['Authorization'] = `BEARER ${jwtAuth}`;
|
|
619
|
+
}
|
|
620
|
+
if (projectAccessKey && projectAccessKey.length > 0) {
|
|
621
|
+
headers['X-Access-Key'] = projectAccessKey;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
// before the request is made
|
|
625
|
+
init.headers = _extends({}, init.headers, headers);
|
|
626
|
+
return fetch(input, init);
|
|
627
|
+
};
|
|
628
|
+
this.options = options;
|
|
629
|
+
this.service = new Relayer(options.url, this._fetch);
|
|
630
|
+
if (ethers.ethers.providers.Provider.isProvider(options.provider)) {
|
|
631
|
+
this.provider = options.provider;
|
|
632
|
+
} else {
|
|
633
|
+
const {
|
|
634
|
+
jwtAuth,
|
|
635
|
+
projectAccessKey
|
|
636
|
+
} = this.options;
|
|
637
|
+
const providerConnectionInfo = utils.getEthersConnectionInfo(options.provider.url, projectAccessKey, jwtAuth);
|
|
638
|
+
this.provider = new ethers.ethers.providers.StaticJsonRpcProvider(providerConnectionInfo);
|
|
639
|
+
}
|
|
609
640
|
}
|
|
610
641
|
async waitReceipt(metaTxnId, delay = 1000, maxFails = 5, isCancelled) {
|
|
611
642
|
if (typeof metaTxnId !== 'string') {
|
|
@@ -602,10 +602,41 @@ function isRpcRelayerOptions(obj) {
|
|
|
602
602
|
return obj.url !== undefined && typeof obj.url === 'string' && obj.provider !== undefined && ethers.ethers.providers.Provider.isProvider(obj.provider);
|
|
603
603
|
}
|
|
604
604
|
const fetch = typeof global === 'object' ? global.fetch : window.fetch;
|
|
605
|
+
|
|
606
|
+
// TODO: rename to SequenceRelayer
|
|
605
607
|
class RpcRelayer {
|
|
606
608
|
constructor(options) {
|
|
607
|
-
this.
|
|
608
|
-
|
|
609
|
+
this._fetch = (input, init) => {
|
|
610
|
+
// automatically include jwt and access key auth header to requests
|
|
611
|
+
// if its been set on the api client
|
|
612
|
+
const headers = {};
|
|
613
|
+
const {
|
|
614
|
+
jwtAuth,
|
|
615
|
+
projectAccessKey
|
|
616
|
+
} = this.options;
|
|
617
|
+
if (jwtAuth && jwtAuth.length > 0) {
|
|
618
|
+
headers['Authorization'] = `BEARER ${jwtAuth}`;
|
|
619
|
+
}
|
|
620
|
+
if (projectAccessKey && projectAccessKey.length > 0) {
|
|
621
|
+
headers['X-Access-Key'] = projectAccessKey;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
// before the request is made
|
|
625
|
+
init.headers = _extends({}, init.headers, headers);
|
|
626
|
+
return fetch(input, init);
|
|
627
|
+
};
|
|
628
|
+
this.options = options;
|
|
629
|
+
this.service = new Relayer(options.url, this._fetch);
|
|
630
|
+
if (ethers.ethers.providers.Provider.isProvider(options.provider)) {
|
|
631
|
+
this.provider = options.provider;
|
|
632
|
+
} else {
|
|
633
|
+
const {
|
|
634
|
+
jwtAuth,
|
|
635
|
+
projectAccessKey
|
|
636
|
+
} = this.options;
|
|
637
|
+
const providerConnectionInfo = utils.getEthersConnectionInfo(options.provider.url, projectAccessKey, jwtAuth);
|
|
638
|
+
this.provider = new ethers.ethers.providers.StaticJsonRpcProvider(providerConnectionInfo);
|
|
639
|
+
}
|
|
609
640
|
}
|
|
610
641
|
async waitReceipt(metaTxnId, delay = 1000, maxFails = 5, isCancelled) {
|
|
611
642
|
if (typeof metaTxnId !== 'string') {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ethers, providers, Signer } from 'ethers';
|
|
2
|
-
import { logger,
|
|
2
|
+
import { logger, getEthersConnectionInfo } from '@0xsequence/utils';
|
|
3
3
|
import { walletContracts } from '@0xsequence/abi';
|
|
4
4
|
import { commons } from '@0xsequence/core';
|
|
5
5
|
|
|
@@ -598,10 +598,41 @@ function isRpcRelayerOptions(obj) {
|
|
|
598
598
|
return obj.url !== undefined && typeof obj.url === 'string' && obj.provider !== undefined && ethers.providers.Provider.isProvider(obj.provider);
|
|
599
599
|
}
|
|
600
600
|
const fetch = typeof global === 'object' ? global.fetch : window.fetch;
|
|
601
|
+
|
|
602
|
+
// TODO: rename to SequenceRelayer
|
|
601
603
|
class RpcRelayer {
|
|
602
604
|
constructor(options) {
|
|
603
|
-
this.
|
|
604
|
-
|
|
605
|
+
this._fetch = (input, init) => {
|
|
606
|
+
// automatically include jwt and access key auth header to requests
|
|
607
|
+
// if its been set on the api client
|
|
608
|
+
const headers = {};
|
|
609
|
+
const {
|
|
610
|
+
jwtAuth,
|
|
611
|
+
projectAccessKey
|
|
612
|
+
} = this.options;
|
|
613
|
+
if (jwtAuth && jwtAuth.length > 0) {
|
|
614
|
+
headers['Authorization'] = `BEARER ${jwtAuth}`;
|
|
615
|
+
}
|
|
616
|
+
if (projectAccessKey && projectAccessKey.length > 0) {
|
|
617
|
+
headers['X-Access-Key'] = projectAccessKey;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
// before the request is made
|
|
621
|
+
init.headers = _extends({}, init.headers, headers);
|
|
622
|
+
return fetch(input, init);
|
|
623
|
+
};
|
|
624
|
+
this.options = options;
|
|
625
|
+
this.service = new Relayer(options.url, this._fetch);
|
|
626
|
+
if (ethers.providers.Provider.isProvider(options.provider)) {
|
|
627
|
+
this.provider = options.provider;
|
|
628
|
+
} else {
|
|
629
|
+
const {
|
|
630
|
+
jwtAuth,
|
|
631
|
+
projectAccessKey
|
|
632
|
+
} = this.options;
|
|
633
|
+
const providerConnectionInfo = getEthersConnectionInfo(options.provider.url, projectAccessKey, jwtAuth);
|
|
634
|
+
this.provider = new ethers.providers.StaticJsonRpcProvider(providerConnectionInfo);
|
|
635
|
+
}
|
|
605
636
|
}
|
|
606
637
|
async waitReceipt(metaTxnId, delay = 1000, maxFails = 5, isCancelled) {
|
|
607
638
|
if (typeof metaTxnId !== 'string') {
|
|
@@ -8,12 +8,16 @@ export interface RpcRelayerOptions {
|
|
|
8
8
|
url: string;
|
|
9
9
|
};
|
|
10
10
|
url: string;
|
|
11
|
+
projectAccessKey?: string;
|
|
12
|
+
jwtAuth?: string;
|
|
11
13
|
}
|
|
12
14
|
export declare function isRpcRelayerOptions(obj: any): obj is RpcRelayerOptions;
|
|
13
15
|
export declare class RpcRelayer implements Relayer {
|
|
16
|
+
options: RpcRelayerOptions;
|
|
14
17
|
private readonly service;
|
|
15
18
|
readonly provider: ethers.providers.Provider;
|
|
16
19
|
constructor(options: RpcRelayerOptions);
|
|
20
|
+
_fetch: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
|
|
17
21
|
waitReceipt(metaTxnId: string | commons.transaction.SignedTransactionBundle, delay?: number, maxFails?: number, isCancelled?: () => boolean): Promise<proto.GetMetaTxnReceiptReturn>;
|
|
18
22
|
simulate(wallet: string, ...transactions: commons.transaction.Transaction[]): Promise<SimulateResult[]>;
|
|
19
23
|
getFeeOptions(address: string, ...transactions: commons.transaction.Transaction[]): Promise<{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xsequence/relayer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "relayer sub-package for Sequence",
|
|
5
5
|
"repository": "https://github.com/0xsequence/sequence.js/tree/master/packages/relayer",
|
|
6
6
|
"source": "src/index.ts",
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
"author": "Horizon Blockchain Games",
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@0xsequence/abi": "1.
|
|
13
|
-
"@0xsequence/
|
|
14
|
-
"@0xsequence/
|
|
12
|
+
"@0xsequence/abi": "1.4.0",
|
|
13
|
+
"@0xsequence/core": "1.4.0",
|
|
14
|
+
"@0xsequence/utils": "1.4.0"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
17
|
"ethers": ">=5.5 < 6"
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@0xsequence/wallet-contracts": "^1.10.0",
|
|
21
21
|
"ethers": "^5.7.2",
|
|
22
|
-
"@0xsequence/signhub": "1.
|
|
23
|
-
"@0xsequence/tests": "1.
|
|
22
|
+
"@0xsequence/signhub": "1.4.0",
|
|
23
|
+
"@0xsequence/tests": "1.4.0"
|
|
24
24
|
},
|
|
25
25
|
"files": [
|
|
26
26
|
"src",
|
package/src/rpc-relayer/index.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { ethers } from 'ethers'
|
|
|
2
2
|
import { FeeOption, FeeQuote, Relayer, SimulateResult } from '..'
|
|
3
3
|
import * as proto from './relayer.gen'
|
|
4
4
|
import { commons } from '@0xsequence/core'
|
|
5
|
-
import {
|
|
5
|
+
import { getEthersConnectionInfo, logger } from '@0xsequence/utils'
|
|
6
6
|
|
|
7
7
|
export { proto }
|
|
8
8
|
|
|
@@ -18,6 +18,8 @@ const FAILED_STATUSES = [proto.ETHTxnStatus.DROPPED, proto.ETHTxnStatus.PARTIALL
|
|
|
18
18
|
export interface RpcRelayerOptions {
|
|
19
19
|
provider: ethers.providers.Provider | { url: string }
|
|
20
20
|
url: string
|
|
21
|
+
projectAccessKey?: string
|
|
22
|
+
jwtAuth?: string
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
export function isRpcRelayerOptions(obj: any): obj is RpcRelayerOptions {
|
|
@@ -31,15 +33,42 @@ export function isRpcRelayerOptions(obj: any): obj is RpcRelayerOptions {
|
|
|
31
33
|
|
|
32
34
|
const fetch = typeof global === 'object' ? global.fetch : window.fetch
|
|
33
35
|
|
|
36
|
+
// TODO: rename to SequenceRelayer
|
|
34
37
|
export class RpcRelayer implements Relayer {
|
|
35
38
|
private readonly service: proto.Relayer
|
|
36
39
|
public readonly provider: ethers.providers.Provider
|
|
37
40
|
|
|
38
|
-
constructor(options: RpcRelayerOptions) {
|
|
39
|
-
this.service = new proto.Relayer(options.url,
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
constructor(public options: RpcRelayerOptions) {
|
|
42
|
+
this.service = new proto.Relayer(options.url, this._fetch)
|
|
43
|
+
|
|
44
|
+
if (ethers.providers.Provider.isProvider(options.provider)) {
|
|
45
|
+
this.provider = options.provider
|
|
46
|
+
} else {
|
|
47
|
+
const { jwtAuth, projectAccessKey } = this.options
|
|
48
|
+
const providerConnectionInfo = getEthersConnectionInfo(options.provider.url, projectAccessKey, jwtAuth)
|
|
49
|
+
this.provider = new ethers.providers.StaticJsonRpcProvider(providerConnectionInfo)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
_fetch = (input: RequestInfo, init?: RequestInit): Promise<Response> => {
|
|
54
|
+
// automatically include jwt and access key auth header to requests
|
|
55
|
+
// if its been set on the api client
|
|
56
|
+
const headers: { [key: string]: any } = {}
|
|
57
|
+
|
|
58
|
+
const { jwtAuth, projectAccessKey } = this.options
|
|
59
|
+
|
|
60
|
+
if (jwtAuth && jwtAuth.length > 0) {
|
|
61
|
+
headers['Authorization'] = `BEARER ${jwtAuth}`
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (projectAccessKey && projectAccessKey.length > 0) {
|
|
65
|
+
headers['X-Access-Key'] = projectAccessKey
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// before the request is made
|
|
69
|
+
init!.headers = { ...init!.headers, ...headers }
|
|
70
|
+
|
|
71
|
+
return fetch(input, init)
|
|
43
72
|
}
|
|
44
73
|
|
|
45
74
|
async waitReceipt(
|