Skip to content

Commit

Permalink
fix: simplify wasm loading on sdk
Browse files Browse the repository at this point in the history
Signed-off-by: Francisco Javier Ribo Labrador <elribonazo@gmail.com>
  • Loading branch information
elribonazo committed Sep 17, 2024
1 parent 02430db commit 263e422
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/mercury/didcomm/Wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
Attachment,
AttachmentData,
} from "didcomm-wasm";
import wasmBuffer from "../../../externals/generated/didcomm-wasm/didcomm_js_bg.wasm"
import wasmBuffer from "didcomm-wasm/didcomm_js_bg.wasm"

import * as Domain from "../../domain";
import { DIDCommDIDResolver } from "./DIDResolver";
Expand All @@ -34,7 +34,7 @@ export class DIDCommWrapper implements DIDCommProtocol {

public static async getDIDComm() {
this.didcomm ??= await import("didcomm-wasm").then(async module => {
const wasmInstance = module.initSync(wasmBuffer);
const wasmInstance = module.initSync({ module: wasmBuffer });
await module.default(wasmInstance);
return module;
});
Expand Down
17 changes: 5 additions & 12 deletions src/pollux/AnoncredsLoader.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// import { Anoncreds } from "../domain/models/Anoncreds";
import type * as Anoncreds from "anoncreds-wasm";



import wasmBuffer from 'anoncreds-wasm/anoncreds_wasm_bg.wasm';
/**
* @class AnoncredsLoader
* handle loading and access of anoncreds library
Expand All @@ -21,18 +24,8 @@ export class AnoncredsLoader {

private async load() {
this.pkg ??= await import("anoncreds-wasm").then(async module => {

let wasmBuffer: Buffer;
if (typeof window !== 'undefined') {
const wasmModule = await import("../../externals/generated/anoncreds-wasm/anoncreds_wasm_bg.wasm")
wasmBuffer = wasmModule.default as any
module.initSync(wasmBuffer);

} else {
const wasmModule = await import("../../externals/generated/anoncreds-wasm/anoncreds_wasm_bg.wasm")
wasmBuffer = wasmModule.default as any
module.initSync(wasmBuffer);
}
const wasmInstance = module.initSync({ module: wasmBuffer });
await module.default(wasmInstance);
return module
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/pollux/Pollux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ export default class Pollux implements IPollux {
async start() {
this._anoncreds = await AnoncredsLoader.getInstance();
this._jwe ??= await import("jwe-wasm").then(async module => {
const wasmInstance = module.initSync(wasmBuffer);
const wasmInstance = module.initSync({ module: wasmBuffer });
await module.default(wasmInstance);
return module;
});
Expand Down

0 comments on commit 263e422

Please sign in to comment.