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.web.ts
62 lines (55 loc) · 1.59 KB
/
index.web.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";
/**
*
* @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");
return import("saito-wasm/pkg/web")
.then((s: any) => {
return s.default().then(() => {
return s;
});
})
.then((s) => {
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;
console.log("init output = ", s);
Saito.setWasmMemory(s.memory);
return Saito.initialize(configs, sharedMethods, factory, privateKey, logLevel);
});
}
export default Saito;