@fireblocks/fireblocks-json-rpc 0.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/README.md +88 -0
- package/dist/package.json +60 -0
- package/dist/src/cli.d.ts +3 -0
- package/dist/src/cli.d.ts.map +1 -0
- package/dist/src/cli.js +63 -0
- package/dist/src/cli.js.map +1 -0
- package/dist/src/command.d.ts +3 -0
- package/dist/src/command.d.ts.map +1 -0
- package/dist/src/command.js +84 -0
- package/dist/src/command.js.map +1 -0
- package/dist/src/constants.d.ts +10 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.js +17 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +21 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/server.d.ts +9 -0
- package/dist/src/server.d.ts.map +1 -0
- package/dist/src/server.js +104 -0
- package/dist/src/server.js.map +1 -0
- package/dist/src/types.d.ts +14 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +3 -0
- package/dist/src/types.js.map +1 -0
- package/package.json +60 -0
package/README.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# Fireblocks Local JSON-RPC
|
|
2
|
+
> **Warning**
|
|
3
|
+
> This package is in a beta stage and should be used at your own risk.
|
|
4
|
+
> The provided interfaces might go through backwards-incompatibale changes.
|
|
5
|
+
> For a more stable library (with a different paradigm) you can use [Fireblocks Web3 Provider](https://github.com/fireblocks/fireblocks-web3-provider)
|
|
6
|
+
|
|
7
|
+
`fireblocks-json-rpc` is a command-line [JSON-RPC](https://ethereum.org/en/developers/docs/apis/json-rpc/) server powered by the Fireblocks API.
|
|
8
|
+
Its goal is to make it easy for Fireblocks users to interact with EVM chains.
|
|
9
|
+
|
|
10
|
+
Additional SDKs:
|
|
11
|
+
* [Fireblocks Web3 Provider](https://github.com/fireblocks/fireblocks-web3-provider)
|
|
12
|
+
* [Fireblocks Hardhat Plugin](https://github.com/fireblocks/hardhat-fireblocks)
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
```bash
|
|
16
|
+
npm install -g @fireblocks/fireblocks-json-rpc
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
```sh
|
|
21
|
+
$ fireblocks-json-rpc --help
|
|
22
|
+
_____ _ _ _ _ _ ____ ___ _ _ ____ ____ ____
|
|
23
|
+
| ___(_)_ __ ___| |__ | | ___ ___| | _____ | / ___| / _ \| \ | | | _ \| _ \ / ___|
|
|
24
|
+
| |_ | | '__/ _ \ '_ \| |/ _ \ / __| |/ / __| _ | \___ \| | | | \| |_____| |_) | |_) | |
|
|
25
|
+
| _| | | | | __/ |_) | | (_) | (__| <\__ \ | |_| |___) | |_| | |\ |_____| _ <| __/| |___
|
|
26
|
+
|_| |_|_| \___|_.__/|_|\___/ \___|_|\_\___/ \___/|____/ \___/|_| \_| |_| \_\_| \____|
|
|
27
|
+
|
|
28
|
+
Usage: fireblocks-json-rpc [options] [-- tool [argument ...]]
|
|
29
|
+
|
|
30
|
+
A CLI for running a local Ethereum JSON-RPC server powered by Fireblocks
|
|
31
|
+
|
|
32
|
+
Options:
|
|
33
|
+
--apiKey <key> Fireblocks API key (env: FIREBLOCKS_API_KEY)
|
|
34
|
+
--privateKey <path_or_contents> Fireblocks API private key (env: FIREBLOCKS_API_PRIVATE_KEY_PATH)
|
|
35
|
+
--chainId [chainId] either chainId or rpcUrl must be provided (env: FIREBLOCKS_CHAIN_ID)
|
|
36
|
+
--rpcUrl [rpcUrl] either rpcUrl or chainId must be provided (env: FIREBLOCKS_RPC_URL)
|
|
37
|
+
--http run an http server instead of using IPC (env: FIREBLOCKS_HTTP)
|
|
38
|
+
--port [port] http server port (env: FIREBLOCKS_PORT)
|
|
39
|
+
--host [host] http server host (env: FIREBLOCKS_HOST)
|
|
40
|
+
--path [path] http api endpoint path (env: FIREBLOCKS_PATH)
|
|
41
|
+
--ipcPath [path] IPC path to listen on, defaults to '~/.fireblocks/json-rpc.ipc' on linux and macos, and '\\.\pipe\fireblocks-json-rpc.ipc' on
|
|
42
|
+
windows (default: "/Users/user/.fireblocks/json-rpc.ipc", env: FIREBLOCKS_IPC_PATH)
|
|
43
|
+
--env [env_var_name] sets the listening address as an environment variable (default: "FIREBLOCKS_JSON_RPC_ADDRESS", env: FIREBLOCKS_JSON_RPC_ENV_VAR)
|
|
44
|
+
--vaultAccountIds [vaultAccountIds] Fireblocks Web3 Provider option (env: FIREBLOCKS_VAULT_ACCOUNT_IDS)
|
|
45
|
+
--apiBaseUrl [apiBaseUrl] Fireblocks Web3 Provider option (env: FIREBLOCKS_API_BASE_URL)
|
|
46
|
+
--fallbackFeeLevel [fallbackFeeLevel] Fireblocks Web3 Provider option (env: FIREBLOCKS_FALLBACK_FEE_LEVEL)
|
|
47
|
+
--note [note] Fireblocks Web3 Provider option (default: "Created by Fireblocks JSON-RPC", env: FIREBLOCKS_NOTE)
|
|
48
|
+
--pollingInterval [pollingInterval] Fireblocks Web3 Provider option (env: FIREBLOCKS_POLLING_INTERVAL)
|
|
49
|
+
--oneTimeAddressesEnabled [oneTimeAddressesEnabled] Fireblocks Web3 Provider option (env: FIREBLOCKS_ONE_TIME_ADDRESSES_ENABLED)
|
|
50
|
+
--externalTxId [externalTxId] Fireblocks Web3 Provider option (env: FIREBLOCKS_EXTERNAL_TX_ID)
|
|
51
|
+
--gaslessGasTankVaultId [gaslessGasTankVaultId] Fireblocks Web3 Provider option (env: FIREBLOCKS_GAS_TANK_VAULT_ID)
|
|
52
|
+
--userAgent [userAgent] Fireblocks Web3 Provider option (env: FIREBLOCKS_USER_AGENT)
|
|
53
|
+
-q, --quiet don't print anything (env: FIREBLOCKS_QUIET)
|
|
54
|
+
-v, --verbose print a lot of stuff, useful for debugging, same as setting DEBUG=fireblocks-json-rpc (env: FIREBLOCKS_VERBOSE)
|
|
55
|
+
-r, --raw only output the listening address (env: FIREBLOCKS_VERBOSE)
|
|
56
|
+
--version output the version number
|
|
57
|
+
-h, --help display help for command
|
|
58
|
+
|
|
59
|
+
Learn more about the Fireblocks Web3 Provider configuration options at
|
|
60
|
+
https://github.com/fireblocks/fireblocks-web3-provider#fireblocksproviderconfig
|
|
61
|
+
|
|
62
|
+
Examples:
|
|
63
|
+
Basic usage:
|
|
64
|
+
$ fireblocks-json-rpc --apiKey <key> --privateKey <path_or_contents> --chainId <chainId>
|
|
65
|
+
$ fireblocks-json-rpc --apiKey <key> --privateKey <path_or_contents> --rpcUrl <rpcUrl>
|
|
66
|
+
|
|
67
|
+
Using environment variables:
|
|
68
|
+
$ FIREBLOCKS_API_KEY=<key> FIREBLOCKS_API_PRIVATE_KEY_PATH=<path_or_contents> FIREBLOCKS_CHAIN_ID=<chainId> fireblocks-json-rpc
|
|
69
|
+
|
|
70
|
+
Run another tool using "--" (with environment variables already set):
|
|
71
|
+
$ fireblocks-json-rpc --http -- cast estimate 0x5fe5a74b7628c43514DB077d5E112cf6593ed8D3 "increment()" --rpc-url {}
|
|
72
|
+
$ fireblocks-json-rpc --chainId 5 --http -- cast estimate 0x5fe5a74b7628c43514DB077d5E112cf6593ed8D3 "increment()" --rpc-url {}
|
|
73
|
+
|
|
74
|
+
Print requests and responses using --verbose:
|
|
75
|
+
$ fireblocks-json-rpc --verbose --http -- cast estimate 0x5fe5a74b7628c43514DB077d5E112cf6593ed8D3 "increment()" --rpc-url {}
|
|
76
|
+
|
|
77
|
+
Using a sandbox workspace with --apiBaseUrl:
|
|
78
|
+
$ fireblocks-json-rpc --apiBaseUrl https://sandbox-api.fireblocks.io --apiKey <key> --privateKey <path_or_contents> --chainId <chainId>
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Developemnt
|
|
82
|
+
|
|
83
|
+
### Installation
|
|
84
|
+
```bash
|
|
85
|
+
npm install
|
|
86
|
+
npm run build
|
|
87
|
+
npm install -g .
|
|
88
|
+
```
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fireblocks/fireblocks-json-rpc",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"repository": "github:fireblocks/fireblocks-web3-provider",
|
|
6
|
+
"author": "Fireblocks",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"ethereum",
|
|
10
|
+
"smart-contracts",
|
|
11
|
+
"wallet",
|
|
12
|
+
"fireblocks",
|
|
13
|
+
"jsonrpc",
|
|
14
|
+
"web3",
|
|
15
|
+
"crypto",
|
|
16
|
+
"cryptocurrency",
|
|
17
|
+
"dapp",
|
|
18
|
+
"evm"
|
|
19
|
+
],
|
|
20
|
+
"main": "dist/src/index.js",
|
|
21
|
+
"types": "dist/src/index.d.ts",
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsc",
|
|
27
|
+
"start": "npm run build && node dist/src/cli.js",
|
|
28
|
+
"test": "npm run build && npm install -g . && mocha --exit --recursive 'test/**/*.test.ts'",
|
|
29
|
+
"prepare": "npm run build"
|
|
30
|
+
},
|
|
31
|
+
"bin": {
|
|
32
|
+
"fireblocks-json-rpc": "./dist/src/cli.js"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist/",
|
|
36
|
+
"LICENSE",
|
|
37
|
+
"README.md"
|
|
38
|
+
],
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@fireblocks/fireblocks-web3-provider": "^1.1.3",
|
|
41
|
+
"commander": "^9.4.1",
|
|
42
|
+
"debug": "^4.3.4",
|
|
43
|
+
"dotenv": "^16.0.3",
|
|
44
|
+
"express": "^4.18.2",
|
|
45
|
+
"figlet": "^1.5.2",
|
|
46
|
+
"tslib": "^2.4.1"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/chai": "^4.3.4",
|
|
50
|
+
"@types/debug": "^4.1.7",
|
|
51
|
+
"@types/express": "^4.17.15",
|
|
52
|
+
"@types/figlet": "^1.5.5",
|
|
53
|
+
"@types/mocha": "^10.0.1",
|
|
54
|
+
"@types/node": "^18.11.18",
|
|
55
|
+
"chai": "^4.3.7",
|
|
56
|
+
"mocha": "^10.2.0",
|
|
57
|
+
"ts-node": "^10.9.1",
|
|
58
|
+
"typescript": "^4.9.4"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/src/cli.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const _1 = require(".");
|
|
8
|
+
const command_1 = require("./command");
|
|
9
|
+
const child_process_1 = require("child_process");
|
|
10
|
+
const constants_1 = require("./constants");
|
|
11
|
+
const process_1 = require("process");
|
|
12
|
+
const debug_1 = __importDefault(require("debug"));
|
|
13
|
+
const debug = (0, debug_1.default)(constants_1.DEBUG_NAMESPACE);
|
|
14
|
+
async function main() {
|
|
15
|
+
const command = (0, command_1.createFireblocksJsonRpcCommand)().parse();
|
|
16
|
+
const options = command.opts();
|
|
17
|
+
const log = (message) => !options.quiet && !options.raw && console.log(message);
|
|
18
|
+
if (options.verbose) {
|
|
19
|
+
debug_1.default.enable(constants_1.DEBUG_NAMESPACE);
|
|
20
|
+
}
|
|
21
|
+
if (!options.chainId && !options.rpcUrl) {
|
|
22
|
+
return console.error("error: chainId or rpcUrl must be provided");
|
|
23
|
+
}
|
|
24
|
+
log(constants_1.asciiTitle);
|
|
25
|
+
const { server, address } = await (0, _1.createServer)(options);
|
|
26
|
+
const args = command.args.map(arg => arg.replace("{}", address));
|
|
27
|
+
if (options.raw) {
|
|
28
|
+
console.log(address);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
log(`Fireblocks JSON-RPC server listening on\n${address}\n`);
|
|
32
|
+
}
|
|
33
|
+
if (command.args.length > 0) {
|
|
34
|
+
log(`Running command:\n${args.join(' ')}\n`);
|
|
35
|
+
if (options.env) {
|
|
36
|
+
process_1.env[options.env] = address;
|
|
37
|
+
}
|
|
38
|
+
delete process_1.env['FIREBLOCKS_API_PRIVATE_KEY_PATH'];
|
|
39
|
+
delete process_1.env['FIREBLOCKS_API_KEY'];
|
|
40
|
+
let process;
|
|
41
|
+
try {
|
|
42
|
+
process = (0, child_process_1.spawn)(command.args[0], args.slice(1), { stdio: "inherit" });
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
server.close();
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
const onExit = (code) => {
|
|
49
|
+
debug(`Child process exited with code ${code}`);
|
|
50
|
+
server.close();
|
|
51
|
+
(0, process_1.exit)(code === null ? 1 : code);
|
|
52
|
+
};
|
|
53
|
+
process.on("exit", onExit);
|
|
54
|
+
process.on("disconnect", () => {
|
|
55
|
+
onExit(null);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
main().catch((error) => {
|
|
60
|
+
console.error(error);
|
|
61
|
+
process.exitCode = 1;
|
|
62
|
+
});
|
|
63
|
+
//# sourceMappingURL=cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":";;;;;;AAEA,wBAAgC;AAChC,uCAA0D;AAC1D,iDAAqC;AACrC,2CAAyD;AACzD,qCAAmC;AACnC,kDAA0B;AAE1B,MAAM,KAAK,GAAG,IAAA,eAAK,EAAC,2BAAe,CAAC,CAAC;AAErC,KAAK,UAAU,IAAI;I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AG,CAAC,oBAAoB,CAAC,CAAA;QAEhC,IAAI,OAAO,CAAA;QACX,IAAI;YACA,OAAO,GAAG,IAAA,qBAAK,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAA;SACxE;QAAC,OAAO,KAAK,EAAE;YACZ,MAAM,CAAC,KAAK,EAAE,CAAA;YACd,MAAM,KAAK,CAAA;SACd;QAED,MAAM,MAAM,GAAG,CAAC,IAAmB,EAAE,EAAE;YACnC,KAAK,CAAC,kCAAkC,IAAI,EAAE,CAAC,CAAA;YAC/C,MAAM,CAAC,KAAK,EAAE,CAAA;YACd,IAAA,cAAI,EAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;QAClC,CAAC,CAAA;QACD,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QAC1B,OAAO,CAAC,EAAE,CAAC,YAAY,EAAE,GAAG,EAAE;YAC1B,MAAM,CAAC,IAAI,CAAC,CAAA;QAChB,CAAC,CAAC,CAAA;KACL;AACL,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACnB,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACrB,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AACzB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../src/command.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAU,MAAM,WAAW,CAAA;AAI3C,wBAAgB,8BAA8B,YA0D7C"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.createFireblocksJsonRpcCommand = void 0;
|
|
27
|
+
const dotenv = __importStar(require("dotenv"));
|
|
28
|
+
dotenv.config();
|
|
29
|
+
const commander_1 = require("commander");
|
|
30
|
+
const package_json_1 = require("../package.json");
|
|
31
|
+
const constants_1 = require("./constants");
|
|
32
|
+
function createFireblocksJsonRpcCommand() {
|
|
33
|
+
return new commander_1.Command().usage('[options] [-- tool [argument ...]]')
|
|
34
|
+
.description("A CLI for running a local Ethereum JSON-RPC server powered by Fireblocks")
|
|
35
|
+
.addOption(new commander_1.Option("--apiKey <key>", "Fireblocks API key").env("FIREBLOCKS_API_KEY").makeOptionMandatory())
|
|
36
|
+
.addOption(new commander_1.Option("--privateKey <path_or_contents>", "Fireblocks API private key").env("FIREBLOCKS_API_PRIVATE_KEY_PATH").makeOptionMandatory())
|
|
37
|
+
.addOption(new commander_1.Option("--chainId [chainId]", "either chainId or rpcUrl must be provided").env("FIREBLOCKS_CHAIN_ID"))
|
|
38
|
+
.addOption(new commander_1.Option("--rpcUrl [rpcUrl]", "either rpcUrl or chainId must be provided").env("FIREBLOCKS_RPC_URL"))
|
|
39
|
+
.addOption(new commander_1.Option("--http", "run an http server instead of using IPC").env("FIREBLOCKS_HTTP"))
|
|
40
|
+
.addOption(new commander_1.Option("--port [port]", "http server port").env("FIREBLOCKS_PORT"))
|
|
41
|
+
.addOption(new commander_1.Option("--host [host]", "http server host").env("FIREBLOCKS_HOST"))
|
|
42
|
+
.addOption(new commander_1.Option("--path [path]", "http api endpoint path").default(undefined, '/${--apiKey}').env("FIREBLOCKS_PATH"))
|
|
43
|
+
.addOption(new commander_1.Option("--ipcPath [path]", `IPC path to listen on, defaults to '${constants_1.LINUX_DEFAULT_IPC_PATH}' on linux and macos, and '${constants_1.WINDOWS_DEFAULT_IPC_PATH}' on windows`).default(constants_1.DEFAULT_IPC_PATH).env("FIREBLOCKS_IPC_PATH"))
|
|
44
|
+
.addOption(new commander_1.Option("--env [env_var_name]", "sets the listening address as an environment variable").default(constants_1.DEFAULT_ENV_VAR).env("FIREBLOCKS_JSON_RPC_ENV_VAR"))
|
|
45
|
+
.addOption(new commander_1.Option("--vaultAccountIds [vaultAccountIds]", constants_1.FIREBLOCKS_WEB3_PROVIDER_OPTION_DESC).env("FIREBLOCKS_VAULT_ACCOUNT_IDS"))
|
|
46
|
+
.addOption(new commander_1.Option("--apiBaseUrl [apiBaseUrl]", constants_1.FIREBLOCKS_WEB3_PROVIDER_OPTION_DESC).env("FIREBLOCKS_API_BASE_URL"))
|
|
47
|
+
.addOption(new commander_1.Option("--fallbackFeeLevel [fallbackFeeLevel]", constants_1.FIREBLOCKS_WEB3_PROVIDER_OPTION_DESC).env("FIREBLOCKS_FALLBACK_FEE_LEVEL"))
|
|
48
|
+
.addOption(new commander_1.Option("--note [note]", constants_1.FIREBLOCKS_WEB3_PROVIDER_OPTION_DESC).default(constants_1.DEFAULT_TX_NOTE).env("FIREBLOCKS_NOTE"))
|
|
49
|
+
.addOption(new commander_1.Option("--pollingInterval [pollingInterval]", constants_1.FIREBLOCKS_WEB3_PROVIDER_OPTION_DESC).env("FIREBLOCKS_POLLING_INTERVAL"))
|
|
50
|
+
.addOption(new commander_1.Option("--oneTimeAddressesEnabled [oneTimeAddressesEnabled]", constants_1.FIREBLOCKS_WEB3_PROVIDER_OPTION_DESC).env("FIREBLOCKS_ONE_TIME_ADDRESSES_ENABLED"))
|
|
51
|
+
.addOption(new commander_1.Option("--externalTxId [externalTxId]", constants_1.FIREBLOCKS_WEB3_PROVIDER_OPTION_DESC).env("FIREBLOCKS_EXTERNAL_TX_ID"))
|
|
52
|
+
.addOption(new commander_1.Option("--userAgent [userAgent]", constants_1.FIREBLOCKS_WEB3_PROVIDER_OPTION_DESC).env("FIREBLOCKS_USER_AGENT"))
|
|
53
|
+
.addOption(new commander_1.Option("-q, --quiet", "don't print anything").env("FIREBLOCKS_QUIET"))
|
|
54
|
+
.addOption(new commander_1.Option("-v, --verbose", `print a lot of stuff, useful for debugging, same as setting DEBUG=${constants_1.DEBUG_NAMESPACE}`).env("FIREBLOCKS_VERBOSE"))
|
|
55
|
+
.addOption(new commander_1.Option("-r, --raw", "only output the listening address").env("FIREBLOCKS_VERBOSE"))
|
|
56
|
+
.version(package_json_1.version, '--version')
|
|
57
|
+
.allowExcessArguments()
|
|
58
|
+
.showHelpAfterError()
|
|
59
|
+
.addHelpText("before", constants_1.asciiTitle)
|
|
60
|
+
.addHelpText("after", `
|
|
61
|
+
Learn more about the Fireblocks Web3 Provider configuration options at
|
|
62
|
+
https://github.com/fireblocks/fireblocks-web3-provider#fireblocksproviderconfig
|
|
63
|
+
|
|
64
|
+
Examples:
|
|
65
|
+
Basic usage:
|
|
66
|
+
$ fireblocks-json-rpc --apiKey <key> --privateKey <path_or_contents> --chainId <chainId>
|
|
67
|
+
$ fireblocks-json-rpc --apiKey <key> --privateKey <path_or_contents> --rpcUrl <rpcUrl>
|
|
68
|
+
|
|
69
|
+
Using environment variables:
|
|
70
|
+
$ FIREBLOCKS_API_KEY=<key> FIREBLOCKS_API_PRIVATE_KEY_PATH=<path_or_contents> FIREBLOCKS_CHAIN_ID=<chainId> fireblocks-json-rpc
|
|
71
|
+
|
|
72
|
+
Run another tool using "--" (with environment variables already set):
|
|
73
|
+
$ fireblocks-json-rpc --http -- cast estimate 0x5fe5a74b7628c43514DB077d5E112cf6593ed8D3 "increment()" --rpc-url {}
|
|
74
|
+
$ fireblocks-json-rpc --chainId 5 --http -- cast estimate 0x5fe5a74b7628c43514DB077d5E112cf6593ed8D3 "increment()" --rpc-url {}
|
|
75
|
+
|
|
76
|
+
Print requests and responses using --verbose:
|
|
77
|
+
$ fireblocks-json-rpc --verbose --http -- cast estimate 0x5fe5a74b7628c43514DB077d5E112cf6593ed8D3 "increment()" --rpc-url {}
|
|
78
|
+
|
|
79
|
+
Using a sandbox workspace with --apiBaseUrl:
|
|
80
|
+
$ fireblocks-json-rpc --apiBaseUrl https://sandbox-api.fireblocks.io --apiKey <key> --privateKey <path_or_contents> --chainId <chainId>
|
|
81
|
+
`);
|
|
82
|
+
}
|
|
83
|
+
exports.createFireblocksJsonRpcCommand = createFireblocksJsonRpcCommand;
|
|
84
|
+
//# sourceMappingURL=command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.js","sourceRoot":"","sources":["../../src/command.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAgC;AAChC,MAAM,CAAC,MAAM,EAAE,CAAA;AAEf,yCAA2C;AAC3C,kDAAyC;AACzC,2CAAqM;AAErM,SAAgB,8BAA8B;IAC1C,OAAO,IAAI,mBAAO,EAAE,CAAC,KAAK,CAAC,oCAAoC,CAAC;SAC3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BAAO,EAAE,WAAW,CAAC;SAE7B,oBAAoB,EAAE;SACtB,kBAAkB,EAAE;SACpB,WAAW,CAAC,QAAQ,EAAE,sBAAU,CAAC;SAEjC,WAAW,CAAC,OAAO,EAAE;;;;;;;;;;;;;;;;;;;;;CAqB7B,CAAC,CAAA;AACF,CAAC;AA1DD,wEA0DC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
export declare const asciiTitle: string;
|
|
3
|
+
export declare const DEBUG_NAMESPACE = "fireblocks-json-rpc";
|
|
4
|
+
export declare const LINUX_DEFAULT_IPC_PATH = "~/.fireblocks/json-rpc.ipc";
|
|
5
|
+
export declare const WINDOWS_DEFAULT_IPC_PATH = "\\\\.\\pipe\\fireblocks-json-rpc.ipc";
|
|
6
|
+
export declare const DEFAULT_IPC_PATH: string;
|
|
7
|
+
export declare const DEFAULT_ENV_VAR = "FIREBLOCKS_JSON_RPC_ADDRESS";
|
|
8
|
+
export declare const FIREBLOCKS_WEB3_PROVIDER_OPTION_DESC = "Fireblocks Web3 Provider option";
|
|
9
|
+
export declare const DEFAULT_TX_NOTE = "Created by Fireblocks JSON-RPC";
|
|
10
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";AAMA,eAAO,MAAM,UAAU,QAAkC,CAAA;AACzD,eAAO,MAAM,eAAe,wBAAwB,CAAA;AACpD,eAAO,MAAM,sBAAsB,+BAA+B,CAAA;AAClE,eAAO,MAAM,wBAAwB,yCAAyC,CAAA;AAC9E,eAAO,MAAM,gBAAgB,QAEqB,CAAA;AAClD,eAAO,MAAM,eAAe,gCAAgC,CAAA;AAC5D,eAAO,MAAM,oCAAoC,oCAAoC,CAAA;AACrF,eAAO,MAAM,eAAe,mCAAmC,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.DEFAULT_TX_NOTE = exports.FIREBLOCKS_WEB3_PROVIDER_OPTION_DESC = exports.DEFAULT_ENV_VAR = exports.DEFAULT_IPC_PATH = exports.WINDOWS_DEFAULT_IPC_PATH = exports.LINUX_DEFAULT_IPC_PATH = exports.DEBUG_NAMESPACE = exports.asciiTitle = void 0;
|
|
5
|
+
const figlet_1 = require("figlet");
|
|
6
|
+
const os_1 = require("os");
|
|
7
|
+
exports.asciiTitle = (0, figlet_1.textSync)("Fireblocks JSON-RPC");
|
|
8
|
+
exports.DEBUG_NAMESPACE = "fireblocks-json-rpc";
|
|
9
|
+
exports.LINUX_DEFAULT_IPC_PATH = "~/.fireblocks/json-rpc.ipc";
|
|
10
|
+
exports.WINDOWS_DEFAULT_IPC_PATH = "\\\\.\\pipe\\fireblocks-json-rpc.ipc";
|
|
11
|
+
exports.DEFAULT_IPC_PATH = process.platform === "win32" ?
|
|
12
|
+
exports.WINDOWS_DEFAULT_IPC_PATH :
|
|
13
|
+
exports.LINUX_DEFAULT_IPC_PATH.replace("~", (0, os_1.homedir)());
|
|
14
|
+
exports.DEFAULT_ENV_VAR = "FIREBLOCKS_JSON_RPC_ADDRESS";
|
|
15
|
+
exports.FIREBLOCKS_WEB3_PROVIDER_OPTION_DESC = "Fireblocks Web3 Provider option";
|
|
16
|
+
exports.DEFAULT_TX_NOTE = "Created by Fireblocks JSON-RPC";
|
|
17
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;;AACA,mCAAiC;AACjC,2BAA4B;AAIf,QAAA,UAAU,GAAG,IAAA,iBAAQ,EAAC,qBAAqB,CAAC,CAAA;AAC5C,QAAA,eAAe,GAAG,qBAAqB,CAAA;AACvC,QAAA,sBAAsB,GAAG,4BAA4B,CAAA;AACrD,QAAA,wBAAwB,GAAG,sCAAsC,CAAA;AACjE,QAAA,gBAAgB,GAAG,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC;IAC1D,gCAAwB,CAAC,CAAC;IAC1B,8BAAsB,CAAC,OAAO,CAAC,GAAG,EAAE,IAAA,YAAO,GAAE,CAAC,CAAA;AACrC,QAAA,eAAe,GAAG,6BAA6B,CAAA;AAC/C,QAAA,oCAAoC,GAAG,iCAAiC,CAAA;AACxE,QAAA,eAAe,GAAG,gCAAgC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./server"), exports);
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
19
|
+
__exportStar(require("./command"), exports);
|
|
20
|
+
__exportStar(require("./constants"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,0CAAwB;AACxB,4CAA0B;AAC1B,8CAA4B"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { ServerConfig } from "./types";
|
|
3
|
+
import net from "net";
|
|
4
|
+
declare function createServer(this: any, config: ServerConfig): Promise<{
|
|
5
|
+
server: net.Server;
|
|
6
|
+
address: string;
|
|
7
|
+
}>;
|
|
8
|
+
export { createServer };
|
|
9
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAIvC,OAAO,GAAG,MAAM,KAAK,CAAC;AA8BtB,iBAAe,YAAY,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC;IAAE,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAyF7G;AAED,OAAO,EAAE,YAAY,EAAE,CAAA"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createServer = void 0;
|
|
7
|
+
const util_1 = require("util");
|
|
8
|
+
const express_1 = __importDefault(require("express"));
|
|
9
|
+
const fireblocks_web3_provider_1 = require("@fireblocks/fireblocks-web3-provider");
|
|
10
|
+
const debug_1 = __importDefault(require("debug"));
|
|
11
|
+
const constants_1 = require("./constants");
|
|
12
|
+
const package_json_1 = require("../package.json");
|
|
13
|
+
const net_1 = __importDefault(require("net"));
|
|
14
|
+
const fs_1 = require("fs");
|
|
15
|
+
const path_1 = require("path");
|
|
16
|
+
const debug = (0, debug_1.default)(constants_1.DEBUG_NAMESPACE);
|
|
17
|
+
async function applyDefaults(config) {
|
|
18
|
+
return Object.assign(Object.assign({}, config), { port: config.port || 0, hostname: config.hostname || "127.0.0.1", httpPath: config.httpPath || `/${config.apiKey}` });
|
|
19
|
+
}
|
|
20
|
+
function serverConfigToWeb3ProviderConfig(config) {
|
|
21
|
+
const web3ProviderConfig = Object.assign(Object.assign({}, config), { userAgent: `${config.userAgent ? `${config.userAgent} ` : ''}fireblocks-json-rpc/${package_json_1.version} (${config.http ? 'HTTP' : 'IPC'})` });
|
|
22
|
+
return web3ProviderConfig;
|
|
23
|
+
}
|
|
24
|
+
function payloadId() {
|
|
25
|
+
const date = Date.now() * Math.pow(10, 3);
|
|
26
|
+
const extra = Math.floor(Math.random() * Math.pow(10, 3));
|
|
27
|
+
return date + extra;
|
|
28
|
+
}
|
|
29
|
+
async function createServer(config) {
|
|
30
|
+
config = await applyDefaults(config);
|
|
31
|
+
const web3ProviderConfig = serverConfigToWeb3ProviderConfig(config);
|
|
32
|
+
const fireblocksProvider = new fireblocks_web3_provider_1.FireblocksWeb3Provider(web3ProviderConfig);
|
|
33
|
+
function receiveRequest(jsonRpcRequest, exteernalResponseCallback) {
|
|
34
|
+
var _a;
|
|
35
|
+
debug("Received request", jsonRpcRequest);
|
|
36
|
+
const responseCallback = (response) => {
|
|
37
|
+
debug("Sending response", response);
|
|
38
|
+
exteernalResponseCallback(response);
|
|
39
|
+
};
|
|
40
|
+
if (jsonRpcRequest.method == "web3_clientVersion") {
|
|
41
|
+
const providerResponse = {
|
|
42
|
+
"id": (_a = jsonRpcRequest.id) !== null && _a !== void 0 ? _a : payloadId(),
|
|
43
|
+
"jsonrpc": jsonRpcRequest.jsonrpc,
|
|
44
|
+
"result": `${web3ProviderConfig.userAgent} fireblocks-web3-provider/${fireblocks_web3_provider_1.version}`
|
|
45
|
+
};
|
|
46
|
+
responseCallback(providerResponse);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
fireblocksProvider.send(jsonRpcRequest, (error, providerResponse) => {
|
|
50
|
+
if (error) {
|
|
51
|
+
debug("Error received from FireblocksWeb3Provider: ", error);
|
|
52
|
+
providerResponse = {
|
|
53
|
+
"id": jsonRpcRequest.id,
|
|
54
|
+
"jsonrpc": jsonRpcRequest.jsonrpc,
|
|
55
|
+
error: Object.assign({ message: error.message, code: -32603 }, error)
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
responseCallback(providerResponse);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
let app;
|
|
63
|
+
if (config.http) {
|
|
64
|
+
app = (0, express_1.default)();
|
|
65
|
+
app.use(express_1.default.json());
|
|
66
|
+
app.disable("x-powered-by");
|
|
67
|
+
app.post(config.httpPath, (req, res) => {
|
|
68
|
+
receiveRequest(req.body, (response) => {
|
|
69
|
+
res.send(response);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
app = net_1.default.createServer(function (socket) {
|
|
75
|
+
socket.on('data', function (data) {
|
|
76
|
+
receiveRequest(JSON.parse(data.toString()), (response) => {
|
|
77
|
+
socket.write(JSON.stringify(response));
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
if (process.platform !== "win32") {
|
|
82
|
+
(0, fs_1.mkdirSync)((0, path_1.dirname)(config.ipcPath), { recursive: true });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const server = config.http ?
|
|
86
|
+
app.listen(config.port, config.hostname) :
|
|
87
|
+
app.listen(config.ipcPath);
|
|
88
|
+
const closeServerOnSignal = (signal) => {
|
|
89
|
+
debug(`${signal} signal received: closing server`);
|
|
90
|
+
server;
|
|
91
|
+
server.close(() => {
|
|
92
|
+
debug('Server closed');
|
|
93
|
+
process.exit(1);
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
process.on('SIGINT', closeServerOnSignal);
|
|
97
|
+
process.on('SIGTERM', closeServerOnSignal);
|
|
98
|
+
await (0, util_1.promisify)(server.once).bind(server)("listening");
|
|
99
|
+
const addr = server.address();
|
|
100
|
+
const address = typeof addr == 'string' ? addr : `http://${addr === null || addr === void 0 ? void 0 : addr.address}:${addr === null || addr === void 0 ? void 0 : addr.port}${config.httpPath}`;
|
|
101
|
+
return { server, address };
|
|
102
|
+
}
|
|
103
|
+
exports.createServer = createServer;
|
|
104
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":";;;;;;AAAA,+BAAgC;AAChC,sDAA6B;AAC7B,mFAAiJ;AAEjJ,kDAA0B;AAC1B,2CAA8C;AAC9C,kDAAyC;AACzC,8CAAsB;AACtB,2BAA+B;AAC/B,+BAA+B;AAE/B,MAAM,KAAK,GAAG,IAAA,eAAK,EAAC,2BAAe,CAAC,CAAC;AAErC,KAAK,UAAU,aAAa,CAAC,MAAoB;IAC7C,uCACO,MAAM,KACT,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,CAAC,EACtB,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,WAAW,EACxC,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,IAAI,MAAM,CAAC,MAAM,EAAE,IACnD;AACL,CAAC;AAED,SAAS,gCAAgC,CAAC,MAAoB;IAC1D,MAAM,kBAAkB,mCACjB,MAAM,KACT,SAAS,EAAE,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC,CA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,CAAE,IAAI,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAA;IAE1G,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAA;AAC9B,CAAC;AAEQ,oCAAY"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { FireblocksProviderConfig } from '@fireblocks/fireblocks-web3-provider';
|
|
2
|
+
type ServerConfig = FireblocksProviderConfig & {
|
|
3
|
+
port?: number;
|
|
4
|
+
hostname?: string;
|
|
5
|
+
httpPath?: string;
|
|
6
|
+
verbose?: boolean;
|
|
7
|
+
quiet?: boolean;
|
|
8
|
+
http?: boolean;
|
|
9
|
+
ipcPath?: string;
|
|
10
|
+
raw?: boolean;
|
|
11
|
+
env?: string;
|
|
12
|
+
};
|
|
13
|
+
export { ServerConfig };
|
|
14
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAA;AAE/E,KAAK,YAAY,GAAG,wBAAwB,GAAG;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;CAChB,CAAA;AAED,OAAO,EAAE,YAAY,EAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fireblocks/fireblocks-json-rpc",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"repository": "github:fireblocks/fireblocks-web3-provider",
|
|
6
|
+
"author": "Fireblocks",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"ethereum",
|
|
10
|
+
"smart-contracts",
|
|
11
|
+
"wallet",
|
|
12
|
+
"fireblocks",
|
|
13
|
+
"jsonrpc",
|
|
14
|
+
"web3",
|
|
15
|
+
"crypto",
|
|
16
|
+
"cryptocurrency",
|
|
17
|
+
"dapp",
|
|
18
|
+
"evm"
|
|
19
|
+
],
|
|
20
|
+
"main": "dist/src/index.js",
|
|
21
|
+
"types": "dist/src/index.d.ts",
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsc",
|
|
27
|
+
"start": "npm run build && node dist/src/cli.js",
|
|
28
|
+
"test": "npm run build && npm install -g . && mocha --exit --recursive 'test/**/*.test.ts'",
|
|
29
|
+
"prepare": "npm run build"
|
|
30
|
+
},
|
|
31
|
+
"bin": {
|
|
32
|
+
"fireblocks-json-rpc": "./dist/src/cli.js"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist/",
|
|
36
|
+
"LICENSE",
|
|
37
|
+
"README.md"
|
|
38
|
+
],
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@fireblocks/fireblocks-web3-provider": "^1.1.3",
|
|
41
|
+
"commander": "^9.4.1",
|
|
42
|
+
"debug": "^4.3.4",
|
|
43
|
+
"dotenv": "^16.0.3",
|
|
44
|
+
"express": "^4.18.2",
|
|
45
|
+
"figlet": "^1.5.2",
|
|
46
|
+
"tslib": "^2.4.1"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/chai": "^4.3.4",
|
|
50
|
+
"@types/debug": "^4.1.7",
|
|
51
|
+
"@types/express": "^4.17.15",
|
|
52
|
+
"@types/figlet": "^1.5.5",
|
|
53
|
+
"@types/mocha": "^10.0.1",
|
|
54
|
+
"@types/node": "^18.11.18",
|
|
55
|
+
"chai": "^4.3.7",
|
|
56
|
+
"mocha": "^10.2.0",
|
|
57
|
+
"ts-node": "^10.9.1",
|
|
58
|
+
"typescript": "^4.9.4"
|
|
59
|
+
}
|
|
60
|
+
}
|