This repository has been archived by the owner on Aug 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.node.ts
62 lines (54 loc) · 1.66 KB
/
index.node.ts
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
import Saito, {LogLevel} from "./saito";
import SharedMethods from "./shared_methods";
import Transaction from "./lib/transaction";
import Slip from "./lib/slip";
import Block from "./lib/block";
import Peer from "./lib/peer";
import Factory from "./lib/factory";
import Wallet from "./lib/wallet";
import Blockchain from "./lib/blockchain";
import PeerService from "./lib/peer_service";
import PeerServiceList from "./lib/peer_service_list";
// import Config from "./lib/config";
const NODE_MAJOR_VERSION = parseInt(process.versions.node.split(".")[0]);
if (NODE_MAJOR_VERSION < 19) {
let cr = require("crypto");
globalThis.crypto = cr.webcrypto;
}
/**
*
* @param configs
* @param sharedMethods
* @param factory
* @param privateKey
* @param logLevel
*/
export async function initialize(
configs: any,
sharedMethods: SharedMethods,
factory: Factory,
privateKey: string,
logLevel: LogLevel = LogLevel.Info
) {
if (Saito.getLibInstance()) {
console.error("saito already initialized");
return;
}
console.log("initializing saito-js");
// let saito = await import("saito-wasm/dist/server");
let saito = await import("saito-wasm/pkg/node");
console.log("wasm lib loaded");
let s = await saito.default;
Saito.setLibInstance(s);
Transaction.Type = s.WasmTransaction;
Slip.Type = s.WasmSlip;
Block.Type = s.WasmBlock;
Peer.Type = s.WasmPeer;
Wallet.Type = s.WasmWallet;
Blockchain.Type = s.WasmBlockchain;
PeerService.Type = s.WasmPeerService;
PeerServiceList.Type = s.WasmPeerServiceList;
// Config.Type = s.WasmConfiguration;
return Saito.initialize(configs, sharedMethods, factory, privateKey, logLevel);
}
export default Saito;