@@ -18,6 +18,79 @@ async function loadModule() {
18
18
}
19
19
}
20
20
21
+ class CModuleLoader {
22
+ private _wasm : CModule | null = null ;
23
+
24
+ get get ( ) : CModule {
25
+ if ( this . _wasm === null ) {
26
+ throw new Error ( "C has not been loaded" ) ;
27
+ }
28
+ return this . _wasm ;
29
+ }
30
+
31
+ async load ( ) : Promise < void > {
32
+ if ( this . _wasm !== null ) {
33
+ return ;
34
+ }
35
+
36
+ if ( process . browser ) {
37
+ this . _wasm = await import ( "@dcspark/cardano-multiplatform-lib-browser" ) ;
38
+ } else {
39
+ this . _wasm = await import ( "@dcspark/cardano-multiplatform-lib-nodejs" ) ;
40
+ }
41
+ }
42
+ }
43
+
44
+ class UModuleLoader {
45
+ private _wasm : UModule | null = null ;
46
+
47
+ get get ( ) : UModule {
48
+ if ( this . _wasm === null ) {
49
+ throw new Error ( "U has not been loaded" ) ;
50
+ }
51
+ return this . _wasm ;
52
+ }
53
+
54
+ async load ( ) : Promise < void > {
55
+ if ( this . _wasm !== null ) {
56
+ return ;
57
+ }
58
+
59
+ if ( process . browser ) {
60
+ this . _wasm = await import ( "uplc-web" ) ;
61
+ } else {
62
+ this . _wasm = await import ( "uplc-node" ) ;
63
+ }
64
+ }
65
+ }
66
+
67
+ class MModuleLoader {
68
+ private _wasm : MModule | null = null ;
69
+
70
+ get get ( ) : MModule {
71
+ if ( this . _wasm === null ) {
72
+ throw new Error ( "M has not been loaded" ) ;
73
+ }
74
+ return this . _wasm ;
75
+ }
76
+
77
+ async load ( ) : Promise < void > {
78
+ if ( this . _wasm !== null ) {
79
+ return ;
80
+ }
81
+
82
+ if ( process . browser ) {
83
+ this . _wasm = await import ( "@emurgo/cardano-message-signing-browser" ) ;
84
+ } else {
85
+ this . _wasm = await import ( "@emurgo/cardano-message-signing-nodejs" ) ;
86
+ }
87
+ }
88
+ }
89
+
90
+ export const cModuleLoader : CModuleLoader = new CModuleLoader ( ) ;
91
+ export const uModuleLoader : UModuleLoader = new UModuleLoader ( ) ;
92
+ export const mModuleLoader : MModuleLoader = new MModuleLoader ( ) ;
93
+
21
94
export type {
22
95
Address as CAddress ,
23
96
BigNum as CBigNum ,
@@ -46,7 +119,15 @@ export type {
46
119
WithdrawalBuilderResult as CWithdrawalBuilderResult ,
47
120
} from "@dcspark/cardano-multiplatform-lib-nodejs" ;
48
121
49
- export { C , U , M , loadModule } ;
122
+ export {
123
+ C ,
124
+ U ,
125
+ M ,
126
+ loadModule ,
127
+ cModuleLoader as CModuleLoader ,
128
+ uModuleLoader as UModuleLoader ,
129
+ mModuleLoader as MModuleLoader ,
130
+ } ;
50
131
51
132
declare global {
52
133
namespace NodeJS {
0 commit comments