-
Notifications
You must be signed in to change notification settings - Fork 113
Expand file tree
/
Copy pathindex.mjs
More file actions
121 lines (106 loc) · 3.17 KB
/
Copy pathindex.mjs
File metadata and controls
121 lines (106 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// index.mjs
// Post-quantum packages
import { ApiPromise, WsProvider } from '@quantova/api';
import { Keyring } from '@quantova/keyring';
import { compactFromU8a, hexToU8a, u8aToHex } from '@quantova/util';
import { cryptoWaitReady, setDilithiumWasmCrypto, setFalconWasmCrypto, setSphincspWasmCrypto } from '@quantova/util-crypto';
import * as falconWasm from '@quantova/falcon-wasm';
// Custom post-quantum modules
import QRpcClient from './src/rpc/index.js';
import QuantumWallet from './src/wallet/index.js';
import QuantumSigner from './src/signer/index.js';
import EventSubscriptionManager from './src/events/index.js';
// Extended modules (contracts, ABI, QNS, batch, fees, hooks, REST)
import QRestClient from './src/rest/index.js';
import AbiCodec from './src/abi/index.js';
import QContract from './src/contract/index.js';
import QNS from './src/qns/index.js';
import BatchRequest from './src/batch/index.js';
import FeeOracle from './src/fee/index.js';
import EventHooks from './src/hooks/index.js';
// Legacy utils
import utils from './src/utils/index.js';
const { AddressUtils, BigIntUtils, FormatUtils, HexUtils, NumberUtils, ValidationUtils } = utils;
// Legacy errors
import errors from './src/errors/index.js';
const { ConnectionError, InvalidArgumentError, RpcError, TransactionError } = errors;
// Legacy provider
import provider from './src/provider/index.js';
const { RpcProvider, BrowserProvider } = provider;
class QWeb3 {
/**
* @param {string} url - JSON-RPC endpoint (http/ws).
* @param {Object} [opts] - { restUrl } to enable the REST fallback transport.
*/
constructor(url = 'http://127.0.0.1:9944', opts = {}) {
this.url = url;
this.q = new RpcProvider(url);
this.rpc = new QRpcClient(url);
this.wallet = new QuantumWallet();
this.signer = QuantumSigner;
this.events = new EventSubscriptionManager(url.replace(/^http/, 'ws'));
this.rest = opts.restUrl ? new QRestClient(opts.restUrl) : null;
this.batch = () => new BatchRequest(url);
this.fees = new FeeOracle({ rpc: this.rpc, restClient: this.rest });
this.hooks = new EventHooks({ rpc: this.rpc, events: this.events, restClient: this.rest });
this.abi = AbiCodec;
}
contract(abi, address) {
return new QContract(abi, address, {
rpc: this.rpc,
wallet: this.wallet,
restClient: this.rest,
});
}
qns(registryAddress, qnsOpts = {}) {
return new QNS({
registryAddress,
rpc: this.rpc,
wallet: this.wallet,
restClient: this.rest,
...qnsOpts,
});
}
}
export {
// QWeb3 Wrapper
QWeb3,
// Custom post-quantum modules
QRpcClient,
QuantumWallet,
QuantumSigner,
EventSubscriptionManager,
// Extended modules
QRestClient,
AbiCodec,
QContract,
QNS,
BatchRequest,
FeeOracle,
EventHooks,
// Post-quantum
ApiPromise,
WsProvider,
Keyring,
compactFromU8a,
hexToU8a,
u8aToHex,
cryptoWaitReady,
setDilithiumWasmCrypto,
setFalconWasmCrypto,
setSphincspWasmCrypto,
falconWasm,
// Legacy
AddressUtils,
BigIntUtils,
FormatUtils,
HexUtils,
NumberUtils,
ValidationUtils,
ConnectionError,
InvalidArgumentError,
RpcError,
TransactionError,
RpcProvider,
BrowserProvider
};