@appliedblockchain/silentdatarollup-ethers-provider 1.0.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.
- package/README.md +126 -0
- package/dist/index.d.mts +27 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +159 -0
- package/dist/index.mjs +150 -0
- package/package.json +46 -0
package/README.md
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# Silent Data [Rollup] Providers - Ethers Provider Package
|
|
2
|
+
|
|
3
|
+
## Table of Contents
|
|
4
|
+
|
|
5
|
+
- [Introduction](#introduction)
|
|
6
|
+
- [Prerequisites](#prerequisites)
|
|
7
|
+
- [Integration](#integration)
|
|
8
|
+
- [Basic Usage](#basic-usage)
|
|
9
|
+
- [Installing Basic Usage Dependencies](#installing-basic-usage-dependencies)
|
|
10
|
+
- [Basic Usage Example](#basic-usage-example)
|
|
11
|
+
- [Usage with a Contract](#usage-with-a-contract)
|
|
12
|
+
- [Installing Usage with a Contract Dependencies](#installing-usage-with-a-contract-dependencies)
|
|
13
|
+
- [Usage with a Contract Example](#usage-with-a-contract-example)
|
|
14
|
+
- [Troubleshooting](#troubleshooting)
|
|
15
|
+
- [License](#license)
|
|
16
|
+
- [Additional Resources](#additional-resources)
|
|
17
|
+
|
|
18
|
+
## Introduction
|
|
19
|
+
|
|
20
|
+
Custom providers for Silent Data [Rollup], compatible with ethers.js.
|
|
21
|
+
|
|
22
|
+
## Prerequisites
|
|
23
|
+
|
|
24
|
+
- Node.js (version 18 or higher)
|
|
25
|
+
- npm
|
|
26
|
+
- Basic knowledge of Ethereum and smart contracts
|
|
27
|
+
- Ethers.js v6
|
|
28
|
+
|
|
29
|
+
## Integration
|
|
30
|
+
|
|
31
|
+
### Basic Usage
|
|
32
|
+
|
|
33
|
+
#### Installing Basic Usage Dependencies
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install @appliedblockchain/silentdatarollup-core @appliedblockchain/silentdatarollup-ethers-provider ethers@6
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
#### Basic Usage Example
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
import { NetworkName } from '@appliedblockchain/silentdatarollup-core'
|
|
43
|
+
import {
|
|
44
|
+
NetworkName,
|
|
45
|
+
SilentDataRollupProvider,
|
|
46
|
+
} from '@appliedblockchain/silentdatarollup-ethers-provider'
|
|
47
|
+
import { Wallet } from 'ethers'
|
|
48
|
+
|
|
49
|
+
const providerConfig = {
|
|
50
|
+
rpcUrl: 'SILENT_DATA_ROLLUP_RPC_URL',
|
|
51
|
+
network: NetworkName.TESTNET,
|
|
52
|
+
privateKey: 'YOUR_PRIVATE_KEY',
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const provider = new SilentDataRollupProvider(providerConfig)
|
|
56
|
+
|
|
57
|
+
const balance = await provider.getBalance('YOUR_ADDRESS')
|
|
58
|
+
console.log(balance)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Usage with a Contract
|
|
62
|
+
|
|
63
|
+
#### Installing Usage with a Contract Dependencies
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
npm install @appliedblockchain/silentdatarollup-core @appliedblockchain/silentdatarollup-ethers-provider ethers@6
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
#### Usage with a Contract Example
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import {
|
|
73
|
+
ChainId,
|
|
74
|
+
SilentDataRollupContract,
|
|
75
|
+
} from '@appliedblockchain/silentdatarollup-core'
|
|
76
|
+
import { SilentDataRollupProvider } from '@appliedblockchain/silentdatarollup-ethers-provider'
|
|
77
|
+
import { ethers } from 'ethers'
|
|
78
|
+
|
|
79
|
+
const providerConfig = {
|
|
80
|
+
rpcUrl: 'SILENT_DATA_ROLLUP_RPC_URL',
|
|
81
|
+
network: NetworkName.TESTNET,
|
|
82
|
+
privateKey: 'YOUR_PRIVATE_KEY',
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const provider = new SilentDataRollupProvider(providerConfig)
|
|
86
|
+
|
|
87
|
+
const contractAddress = 'YOUR_CONTRACT_ADDRESS'
|
|
88
|
+
const abi = [
|
|
89
|
+
/* Your contract ABI */
|
|
90
|
+
]
|
|
91
|
+
const methodsToSign = ['method1', 'method2'] // Contract read calls that require signing
|
|
92
|
+
|
|
93
|
+
const contract = new SilentDataRollupContract(
|
|
94
|
+
contractAddress,
|
|
95
|
+
abi,
|
|
96
|
+
provider,
|
|
97
|
+
methodsToSign,
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
// Now you can call "private" contract methods. These calls will be signed,
|
|
101
|
+
// and msg.sender will be available in the contract, representing the signer's address.
|
|
102
|
+
const privateMethodResult = await contract.method1('param1', 'param2')
|
|
103
|
+
console.log('Private method result:', privateMethodResult)
|
|
104
|
+
|
|
105
|
+
// You can also call methods that don't require signing.
|
|
106
|
+
// These calls won't include a signature, and msg.sender won't be available in the contract.
|
|
107
|
+
const publicMethodResult = await contract.method3('param1', 'param2')
|
|
108
|
+
console.log('Public method result:', publicMethodResult)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## License
|
|
112
|
+
|
|
113
|
+
This project is licensed under the [MIT License](LICENSE).
|
|
114
|
+
|
|
115
|
+
## Troubleshooting
|
|
116
|
+
|
|
117
|
+
If you encounter any issues, please check the following:
|
|
118
|
+
|
|
119
|
+
1. Ensure you're using the correct RPC URL for your desired network.
|
|
120
|
+
2. Verify that your private key is correctly set.
|
|
121
|
+
3. Ensure that your token is active on the SilentData AppChains dashboard.
|
|
122
|
+
|
|
123
|
+
## Additional Resources
|
|
124
|
+
|
|
125
|
+
- [Silent Data [Rollup] Documentation](https://docs.silentdata.com)
|
|
126
|
+
- [Ethers.js Documentation](https://docs.ethers.org/v6/)
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Signer, JsonRpcApiProviderOptions, JsonRpcProvider, JsonRpcPayload, JsonRpcResult, FetchRequest } from 'ethers';
|
|
2
|
+
import { BaseConfig, NetworkName } from '@appliedblockchain/silentdatarollup-core';
|
|
3
|
+
|
|
4
|
+
declare const SIGN_RPC_METHODS: string[];
|
|
5
|
+
|
|
6
|
+
interface SilentDataRollupProviderConfig extends BaseConfig {
|
|
7
|
+
rpcUrl: string;
|
|
8
|
+
network?: NetworkName;
|
|
9
|
+
chainId?: number;
|
|
10
|
+
privateKey?: string;
|
|
11
|
+
signer?: Signer;
|
|
12
|
+
options?: JsonRpcApiProviderOptions;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
declare class SilentDataRollupProvider extends JsonRpcProvider {
|
|
16
|
+
private config;
|
|
17
|
+
signer: Signer;
|
|
18
|
+
private baseProvider;
|
|
19
|
+
constructor(config: SilentDataRollupProviderConfig);
|
|
20
|
+
_send(payload: JsonRpcPayload | Array<JsonRpcPayload>): Promise<Array<JsonRpcResult>>;
|
|
21
|
+
static getRequest({ rpcUrl }: {
|
|
22
|
+
rpcUrl: string;
|
|
23
|
+
}): FetchRequest;
|
|
24
|
+
clone(): SilentDataRollupProvider;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { SIGN_RPC_METHODS, SilentDataRollupProvider, type SilentDataRollupProviderConfig };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Signer, JsonRpcApiProviderOptions, JsonRpcProvider, JsonRpcPayload, JsonRpcResult, FetchRequest } from 'ethers';
|
|
2
|
+
import { BaseConfig, NetworkName } from '@appliedblockchain/silentdatarollup-core';
|
|
3
|
+
|
|
4
|
+
declare const SIGN_RPC_METHODS: string[];
|
|
5
|
+
|
|
6
|
+
interface SilentDataRollupProviderConfig extends BaseConfig {
|
|
7
|
+
rpcUrl: string;
|
|
8
|
+
network?: NetworkName;
|
|
9
|
+
chainId?: number;
|
|
10
|
+
privateKey?: string;
|
|
11
|
+
signer?: Signer;
|
|
12
|
+
options?: JsonRpcApiProviderOptions;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
declare class SilentDataRollupProvider extends JsonRpcProvider {
|
|
16
|
+
private config;
|
|
17
|
+
signer: Signer;
|
|
18
|
+
private baseProvider;
|
|
19
|
+
constructor(config: SilentDataRollupProviderConfig);
|
|
20
|
+
_send(payload: JsonRpcPayload | Array<JsonRpcPayload>): Promise<Array<JsonRpcResult>>;
|
|
21
|
+
static getRequest({ rpcUrl }: {
|
|
22
|
+
rpcUrl: string;
|
|
23
|
+
}): FetchRequest;
|
|
24
|
+
clone(): SilentDataRollupProvider;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { SIGN_RPC_METHODS, SilentDataRollupProvider, type SilentDataRollupProviderConfig };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
SIGN_RPC_METHODS: () => SIGN_RPC_METHODS,
|
|
24
|
+
SilentDataRollupProvider: () => SilentDataRollupProvider
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
|
|
28
|
+
// src/constants.ts
|
|
29
|
+
var SIGN_RPC_METHODS = [
|
|
30
|
+
"eth_getTransactionByHash",
|
|
31
|
+
"eth_getBalance",
|
|
32
|
+
"eth_getTransactionCount",
|
|
33
|
+
"eth_getProof",
|
|
34
|
+
"eth_getTransactionReceipt"
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
// src/provider.ts
|
|
38
|
+
var import_silentdatarollup_core = require("@appliedblockchain/silentdatarollup-core");
|
|
39
|
+
var import_ethers = require("ethers");
|
|
40
|
+
function getNetwork(name, chainId) {
|
|
41
|
+
switch (name) {
|
|
42
|
+
case import_silentdatarollup_core.NetworkName.MAINNET:
|
|
43
|
+
return new import_ethers.Network(name, chainId || import_silentdatarollup_core.ChainId.MAINNET);
|
|
44
|
+
case import_silentdatarollup_core.NetworkName.TESTNET:
|
|
45
|
+
return new import_ethers.Network(name, chainId || import_silentdatarollup_core.ChainId.TESTNET);
|
|
46
|
+
default:
|
|
47
|
+
(0, import_ethers.assertArgument)(false, "unsupported network", "network", name);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
var providerDefaultOptions = {
|
|
51
|
+
batchMaxCount: 1
|
|
52
|
+
};
|
|
53
|
+
var SilentDataRollupProvider = class _SilentDataRollupProvider extends import_ethers.JsonRpcProvider {
|
|
54
|
+
constructor(config) {
|
|
55
|
+
if (!config.network) {
|
|
56
|
+
config.network = import_silentdatarollup_core.NetworkName.MAINNET;
|
|
57
|
+
}
|
|
58
|
+
(0, import_ethers.assertArgument)(config.rpcUrl, "rpcUrl is mandatory", "config", config);
|
|
59
|
+
const network = getNetwork(config.network, config.chainId);
|
|
60
|
+
const request = _SilentDataRollupProvider.getRequest({
|
|
61
|
+
rpcUrl: config.rpcUrl
|
|
62
|
+
});
|
|
63
|
+
const combinedOptions = {
|
|
64
|
+
...providerDefaultOptions,
|
|
65
|
+
...config.options
|
|
66
|
+
};
|
|
67
|
+
super(request, network, combinedOptions);
|
|
68
|
+
(0, import_ethers.assertArgument)(
|
|
69
|
+
config.signer || config.privateKey,
|
|
70
|
+
"signer or privateKey is mandatory",
|
|
71
|
+
"config",
|
|
72
|
+
config
|
|
73
|
+
);
|
|
74
|
+
this.baseProvider = new import_silentdatarollup_core.SilentDataRollupBase(config);
|
|
75
|
+
this.config = config;
|
|
76
|
+
this.config.authSignatureType = config.authSignatureType || import_silentdatarollup_core.SignatureType.Raw;
|
|
77
|
+
if (config.signer) {
|
|
78
|
+
try {
|
|
79
|
+
this.signer = config.signer.connect(this);
|
|
80
|
+
} catch {
|
|
81
|
+
this.signer = config.signer;
|
|
82
|
+
}
|
|
83
|
+
} else {
|
|
84
|
+
const wallet = new import_ethers.Wallet(config.privateKey);
|
|
85
|
+
this.signer = wallet.connect(this);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
async _send(payload) {
|
|
89
|
+
if (Array.isArray(payload)) {
|
|
90
|
+
throw new Error("Batch requests are not currently supported");
|
|
91
|
+
}
|
|
92
|
+
if (payload.method === "eth_call" && Array.isArray(payload.params)) {
|
|
93
|
+
const txParams = payload.params[0];
|
|
94
|
+
if (typeof txParams === "object" && txParams !== null) {
|
|
95
|
+
txParams.from = await this.signer.getAddress();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const request = this._getConnection();
|
|
99
|
+
request.body = JSON.stringify(payload);
|
|
100
|
+
request.setHeader("content-type", "application/json");
|
|
101
|
+
const requiresAuthHeaders = import_silentdatarollup_core.SIGN_RPC_METHODS.includes(payload.method) || (0, import_silentdatarollup_core.isSignableContractCall)(
|
|
102
|
+
payload,
|
|
103
|
+
this.baseProvider.contractMethodsToSign,
|
|
104
|
+
this.baseProvider.contract
|
|
105
|
+
);
|
|
106
|
+
if (requiresAuthHeaders) {
|
|
107
|
+
if (this.config.delegate) {
|
|
108
|
+
const {
|
|
109
|
+
[import_silentdatarollup_core.HEADER_DELEGATE]: xDelegate,
|
|
110
|
+
[import_silentdatarollup_core.HEADER_DELEGATE_SIGNATURE]: xDelegateSignature,
|
|
111
|
+
[import_silentdatarollup_core.HEADER_EIP712_DELEGATE_SIGNATURE]: xEip712DelegateSignature
|
|
112
|
+
} = await this.baseProvider.getDelegateHeaders(this);
|
|
113
|
+
request.setHeader(import_silentdatarollup_core.HEADER_DELEGATE, xDelegate);
|
|
114
|
+
if (xDelegateSignature) {
|
|
115
|
+
request.setHeader(import_silentdatarollup_core.HEADER_DELEGATE_SIGNATURE, xDelegateSignature);
|
|
116
|
+
}
|
|
117
|
+
if (xEip712DelegateSignature) {
|
|
118
|
+
request.setHeader(
|
|
119
|
+
import_silentdatarollup_core.HEADER_EIP712_DELEGATE_SIGNATURE,
|
|
120
|
+
xEip712DelegateSignature
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const {
|
|
125
|
+
[import_silentdatarollup_core.HEADER_TIMESTAMP]: xTimestamp,
|
|
126
|
+
[import_silentdatarollup_core.HEADER_SIGNATURE]: xSignature,
|
|
127
|
+
[import_silentdatarollup_core.HEADER_EIP712_SIGNATURE]: xEip712Signature
|
|
128
|
+
} = await this.baseProvider.getAuthHeaders(this, payload);
|
|
129
|
+
request.setHeader(import_silentdatarollup_core.HEADER_TIMESTAMP, xTimestamp);
|
|
130
|
+
if (xSignature) {
|
|
131
|
+
request.setHeader(import_silentdatarollup_core.HEADER_SIGNATURE, xSignature);
|
|
132
|
+
}
|
|
133
|
+
if (xEip712Signature) {
|
|
134
|
+
request.setHeader(import_silentdatarollup_core.HEADER_EIP712_SIGNATURE, xEip712Signature);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const response = await request.send();
|
|
138
|
+
response.assertOk();
|
|
139
|
+
let resp = response.bodyJson;
|
|
140
|
+
if (!Array.isArray(resp)) {
|
|
141
|
+
resp = [resp];
|
|
142
|
+
}
|
|
143
|
+
return resp;
|
|
144
|
+
}
|
|
145
|
+
static getRequest({ rpcUrl }) {
|
|
146
|
+
const request = new import_ethers.FetchRequest(rpcUrl);
|
|
147
|
+
request.allowGzip = true;
|
|
148
|
+
return request;
|
|
149
|
+
}
|
|
150
|
+
clone() {
|
|
151
|
+
const clonedProvider = new _SilentDataRollupProvider(this.config);
|
|
152
|
+
return clonedProvider;
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
156
|
+
0 && (module.exports = {
|
|
157
|
+
SIGN_RPC_METHODS,
|
|
158
|
+
SilentDataRollupProvider
|
|
159
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// src/constants.ts
|
|
2
|
+
var SIGN_RPC_METHODS = [
|
|
3
|
+
"eth_getTransactionByHash",
|
|
4
|
+
"eth_getBalance",
|
|
5
|
+
"eth_getTransactionCount",
|
|
6
|
+
"eth_getProof",
|
|
7
|
+
"eth_getTransactionReceipt"
|
|
8
|
+
];
|
|
9
|
+
|
|
10
|
+
// src/provider.ts
|
|
11
|
+
import {
|
|
12
|
+
ChainId,
|
|
13
|
+
HEADER_DELEGATE,
|
|
14
|
+
HEADER_DELEGATE_SIGNATURE,
|
|
15
|
+
HEADER_EIP712_DELEGATE_SIGNATURE,
|
|
16
|
+
HEADER_EIP712_SIGNATURE,
|
|
17
|
+
HEADER_SIGNATURE,
|
|
18
|
+
HEADER_TIMESTAMP,
|
|
19
|
+
isSignableContractCall,
|
|
20
|
+
NetworkName,
|
|
21
|
+
SIGN_RPC_METHODS as SIGN_RPC_METHODS2,
|
|
22
|
+
SignatureType,
|
|
23
|
+
SilentDataRollupBase
|
|
24
|
+
} from "@appliedblockchain/silentdatarollup-core";
|
|
25
|
+
import {
|
|
26
|
+
assertArgument,
|
|
27
|
+
FetchRequest,
|
|
28
|
+
JsonRpcProvider,
|
|
29
|
+
Network,
|
|
30
|
+
Wallet
|
|
31
|
+
} from "ethers";
|
|
32
|
+
function getNetwork(name, chainId) {
|
|
33
|
+
switch (name) {
|
|
34
|
+
case NetworkName.MAINNET:
|
|
35
|
+
return new Network(name, chainId || ChainId.MAINNET);
|
|
36
|
+
case NetworkName.TESTNET:
|
|
37
|
+
return new Network(name, chainId || ChainId.TESTNET);
|
|
38
|
+
default:
|
|
39
|
+
assertArgument(false, "unsupported network", "network", name);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
var providerDefaultOptions = {
|
|
43
|
+
batchMaxCount: 1
|
|
44
|
+
};
|
|
45
|
+
var SilentDataRollupProvider = class _SilentDataRollupProvider extends JsonRpcProvider {
|
|
46
|
+
constructor(config) {
|
|
47
|
+
if (!config.network) {
|
|
48
|
+
config.network = NetworkName.MAINNET;
|
|
49
|
+
}
|
|
50
|
+
assertArgument(config.rpcUrl, "rpcUrl is mandatory", "config", config);
|
|
51
|
+
const network = getNetwork(config.network, config.chainId);
|
|
52
|
+
const request = _SilentDataRollupProvider.getRequest({
|
|
53
|
+
rpcUrl: config.rpcUrl
|
|
54
|
+
});
|
|
55
|
+
const combinedOptions = {
|
|
56
|
+
...providerDefaultOptions,
|
|
57
|
+
...config.options
|
|
58
|
+
};
|
|
59
|
+
super(request, network, combinedOptions);
|
|
60
|
+
assertArgument(
|
|
61
|
+
config.signer || config.privateKey,
|
|
62
|
+
"signer or privateKey is mandatory",
|
|
63
|
+
"config",
|
|
64
|
+
config
|
|
65
|
+
);
|
|
66
|
+
this.baseProvider = new SilentDataRollupBase(config);
|
|
67
|
+
this.config = config;
|
|
68
|
+
this.config.authSignatureType = config.authSignatureType || SignatureType.Raw;
|
|
69
|
+
if (config.signer) {
|
|
70
|
+
try {
|
|
71
|
+
this.signer = config.signer.connect(this);
|
|
72
|
+
} catch {
|
|
73
|
+
this.signer = config.signer;
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
76
|
+
const wallet = new Wallet(config.privateKey);
|
|
77
|
+
this.signer = wallet.connect(this);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async _send(payload) {
|
|
81
|
+
if (Array.isArray(payload)) {
|
|
82
|
+
throw new Error("Batch requests are not currently supported");
|
|
83
|
+
}
|
|
84
|
+
if (payload.method === "eth_call" && Array.isArray(payload.params)) {
|
|
85
|
+
const txParams = payload.params[0];
|
|
86
|
+
if (typeof txParams === "object" && txParams !== null) {
|
|
87
|
+
txParams.from = await this.signer.getAddress();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const request = this._getConnection();
|
|
91
|
+
request.body = JSON.stringify(payload);
|
|
92
|
+
request.setHeader("content-type", "application/json");
|
|
93
|
+
const requiresAuthHeaders = SIGN_RPC_METHODS2.includes(payload.method) || isSignableContractCall(
|
|
94
|
+
payload,
|
|
95
|
+
this.baseProvider.contractMethodsToSign,
|
|
96
|
+
this.baseProvider.contract
|
|
97
|
+
);
|
|
98
|
+
if (requiresAuthHeaders) {
|
|
99
|
+
if (this.config.delegate) {
|
|
100
|
+
const {
|
|
101
|
+
[HEADER_DELEGATE]: xDelegate,
|
|
102
|
+
[HEADER_DELEGATE_SIGNATURE]: xDelegateSignature,
|
|
103
|
+
[HEADER_EIP712_DELEGATE_SIGNATURE]: xEip712DelegateSignature
|
|
104
|
+
} = await this.baseProvider.getDelegateHeaders(this);
|
|
105
|
+
request.setHeader(HEADER_DELEGATE, xDelegate);
|
|
106
|
+
if (xDelegateSignature) {
|
|
107
|
+
request.setHeader(HEADER_DELEGATE_SIGNATURE, xDelegateSignature);
|
|
108
|
+
}
|
|
109
|
+
if (xEip712DelegateSignature) {
|
|
110
|
+
request.setHeader(
|
|
111
|
+
HEADER_EIP712_DELEGATE_SIGNATURE,
|
|
112
|
+
xEip712DelegateSignature
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const {
|
|
117
|
+
[HEADER_TIMESTAMP]: xTimestamp,
|
|
118
|
+
[HEADER_SIGNATURE]: xSignature,
|
|
119
|
+
[HEADER_EIP712_SIGNATURE]: xEip712Signature
|
|
120
|
+
} = await this.baseProvider.getAuthHeaders(this, payload);
|
|
121
|
+
request.setHeader(HEADER_TIMESTAMP, xTimestamp);
|
|
122
|
+
if (xSignature) {
|
|
123
|
+
request.setHeader(HEADER_SIGNATURE, xSignature);
|
|
124
|
+
}
|
|
125
|
+
if (xEip712Signature) {
|
|
126
|
+
request.setHeader(HEADER_EIP712_SIGNATURE, xEip712Signature);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const response = await request.send();
|
|
130
|
+
response.assertOk();
|
|
131
|
+
let resp = response.bodyJson;
|
|
132
|
+
if (!Array.isArray(resp)) {
|
|
133
|
+
resp = [resp];
|
|
134
|
+
}
|
|
135
|
+
return resp;
|
|
136
|
+
}
|
|
137
|
+
static getRequest({ rpcUrl }) {
|
|
138
|
+
const request = new FetchRequest(rpcUrl);
|
|
139
|
+
request.allowGzip = true;
|
|
140
|
+
return request;
|
|
141
|
+
}
|
|
142
|
+
clone() {
|
|
143
|
+
const clonedProvider = new _SilentDataRollupProvider(this.config);
|
|
144
|
+
return clonedProvider;
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
export {
|
|
148
|
+
SIGN_RPC_METHODS,
|
|
149
|
+
SilentDataRollupProvider
|
|
150
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@appliedblockchain/silentdatarollup-ethers-provider",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Ethers.js provider for Silent Data [Rollup]",
|
|
5
|
+
"author": "Applied Blockchain",
|
|
6
|
+
"homepage": "https://github.com/appliedblockchain/silent-data-rollup-providers#readme",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"ethereum",
|
|
9
|
+
"provider",
|
|
10
|
+
"silentdata",
|
|
11
|
+
"rollup",
|
|
12
|
+
"ethers"
|
|
13
|
+
],
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"repository": "https://github.com/appliedblockchain/silent-data-rollup-providers",
|
|
16
|
+
"main": "dist/index.js",
|
|
17
|
+
"module": "dist/index.mjs",
|
|
18
|
+
"types": "dist/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"import": "./dist/index.mjs",
|
|
22
|
+
"require": "./dist/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
30
|
+
"check-exports": "attw --pack . --profile node16",
|
|
31
|
+
"prepack": "npm run build",
|
|
32
|
+
"test": "jest"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@appliedblockchain/silentdatarollup-core": "1.0.0",
|
|
36
|
+
"ethers": "6.13.2"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/node": "22.5.4",
|
|
40
|
+
"ts-node": "10.9.2",
|
|
41
|
+
"typescript": "5.6.2"
|
|
42
|
+
},
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=18.0.0"
|
|
45
|
+
}
|
|
46
|
+
}
|