Skip to content

Commit

Permalink
Create external modules for wasm (#37)
Browse files Browse the repository at this point in the history
* feat: separated wasm into its own package

* feat: added wasm-web package

* fix: test config with external wasm

* fix: prettier
  • Loading branch information
alexlwn123 authored Sep 24, 2024
1 parent a091101 commit ec6f0c2
Show file tree
Hide file tree
Showing 21 changed files with 1,721 additions and 22 deletions.
7 changes: 7 additions & 0 deletions .changeset/eight-lamps-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@fedimint/fedimint-client-wasm-bundler': patch
'@fedimint/core-web': patch
'@fedimint/fedimint-client-wasm-web': patch
---

Separated wasm dependecies into their own packages
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
CHANGELOG.md
pnpm-lock.yaml
tsconfig.base.json
packages/core-web/wasm/**
packages/wasm-web/**
packages/wasm-bundler/**
tmp/**
*.html
1 change: 0 additions & 1 deletion packages/core-web/.npmrc

This file was deleted.

5 changes: 1 addition & 4 deletions packages/core-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"dependencies": {
"@fedimint/fedimint-client-wasm": "file:./wasm"
"@fedimint/fedimint-client-wasm-bundler": "workspace:*"
},
"bundleDependencies": [
"@fedimint/fedimint-client-wasm"
],
"devDependencies": {
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/core-web/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ export default [
sourcemap: true,
},
plugins: [typescript(), terser()],
external: ['@fedimint/fedimint-client-wasm'],
external: ['@fedimint/fedimint-client-wasm-bundler'],
},
]
3 changes: 2 additions & 1 deletion packages/core-web/src/worker/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ self.onmessage = async (event) => {

try {
if (type === 'init') {
WasmClient = (await import('@fedimint/fedimint-client-wasm')).WasmClient
WasmClient = (await import('@fedimint/fedimint-client-wasm-bundler'))
.WasmClient
self.postMessage({ type: 'initialized', data: {}, requestId })
} else if (type === 'open') {
const { clientName } = payload
Expand Down
7 changes: 7 additions & 0 deletions packages/wasm-bundler/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# @fedimint/fedimint-client-wasm-bundler

This package contains the WebAssembly (Wasm) output of `fedimint-client-wasm` targeting bundler environments. It is generated using `wasm-pack` and is not intended to be used directly.

## Usage

This package is not intended to be used directly. It serves as a build artifact for `fedimint-client-wasm` targeting bundler environments.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@fedimint/fedimint-client-wasm",
"private": true,
"name": "@fedimint/fedimint-client-wasm-bundler",
"type": "module",
"description": "Wasm-pack output for fedimint-client-wasm",
"description": "Wasm-pack output (target bundler) for fedimint-client-wasm",
"version": "0.0.0",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
7 changes: 7 additions & 0 deletions packages/wasm-web/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# @fedimint/fedimint-client-wasm-web

This package contains the WebAssembly (Wasm) output of `fedimint-client-wasm` targeting web environments. It is generated using `wasm-pack` and is not intended to be used directly.

## Usage

This package is not intended to be used directly. It serves as a build artifact for `fedimint-client-wasm` targeting web environments.
190 changes: 190 additions & 0 deletions packages/wasm-web/fedimint_client_wasm.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
/* tslint:disable */
/* eslint-disable */
/**
*/
export class RpcHandle {
free(): void
/**
*/
cancel(): void
}
/**
*/
export class WasmClient {
free(): void
/**
* Open fedimint client with already joined federation.
*
* After you have joined a federation, you can reopen the fedimint client
* with same client_name. Opening client with same name at same time is
* not supported. You can close the current client by calling
* `client.free()`. NOTE: The client will remain active until all the
* running rpc calls have finished.
* @param {string} client_name
* @returns {Promise<WasmClient | undefined>}
*/
static open(client_name: string): Promise<WasmClient | undefined>
/**
* Open a fedimint client by join a federation.
* @param {string} client_name
* @param {string} invite_code
* @returns {Promise<WasmClient>}
*/
static join_federation(
client_name: string,
invite_code: string,
): Promise<WasmClient>
/**
* Call a fedimint client rpc the responses are returned using `cb`
* callback. Each rpc call *can* return multiple responses by calling
* `cb` multiple times. The returned RpcHandle can be used to cancel the
* operation.
* @param {string} module
* @param {string} method
* @param {string} payload
* @param {Function} cb
* @returns {RpcHandle}
*/
rpc(module: string, method: string, payload: string, cb: Function): RpcHandle
}

export type InitInput =
| RequestInfo
| URL
| Response
| BufferSource
| WebAssembly.Module

export interface InitOutput {
readonly memory: WebAssembly.Memory
readonly __wbg_wasmclient_free: (a: number) => void
readonly __wbg_rpchandle_free: (a: number) => void
readonly rpchandle_cancel: (a: number) => void
readonly wasmclient_open: (a: number, b: number) => number
readonly wasmclient_join_federation: (
a: number,
b: number,
c: number,
d: number,
) => number
readonly wasmclient_rpc: (
a: number,
b: number,
c: number,
d: number,
e: number,
f: number,
g: number,
h: number,
) => number
readonly ring_core_0_17_8_bn_mul_mont: (
a: number,
b: number,
c: number,
d: number,
e: number,
f: number,
) => void
readonly rustsecp256k1zkp_v0_8_0_default_illegal_callback_fn: (
a: number,
b: number,
) => void
readonly rustsecp256k1zkp_v0_8_0_default_error_callback_fn: (
a: number,
b: number,
) => void
readonly rustsecp256k1_v0_6_1_context_create: (a: number) => number
readonly rustsecp256k1_v0_6_1_context_destroy: (a: number) => void
readonly rustsecp256k1_v0_6_1_default_illegal_callback_fn: (
a: number,
b: number,
) => void
readonly rustsecp256k1_v0_6_1_default_error_callback_fn: (
a: number,
b: number,
) => void
readonly rustsecp256k1_v0_8_1_context_create: (a: number) => number
readonly rustsecp256k1_v0_8_1_context_destroy: (a: number) => void
readonly rustsecp256k1_v0_8_1_default_illegal_callback_fn: (
a: number,
b: number,
) => void
readonly rustsecp256k1_v0_8_1_default_error_callback_fn: (
a: number,
b: number,
) => void
readonly __wbindgen_malloc: (a: number, b: number) => number
readonly __wbindgen_realloc: (
a: number,
b: number,
c: number,
d: number,
) => number
readonly __wbindgen_export_2: WebAssembly.Table
readonly __wbindgen_add_to_stack_pointer: (a: number) => number
readonly _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h8697e16cd1c64495: (
a: number,
b: number,
c: number,
d: number,
) => void
readonly _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h31a94cc9a05d5ca0: (
a: number,
b: number,
c: number,
) => void
readonly _dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h4d11ec113460b95d: (
a: number,
b: number,
) => void
readonly _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__he7056307c6986185: (
a: number,
b: number,
c: number,
d: number,
) => void
readonly _dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h5b16159cdfa166b0: (
a: number,
b: number,
) => void
readonly _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hebf1bd391d12b3cb: (
a: number,
b: number,
c: number,
) => void
readonly _dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h09ee3e3abd173580: (
a: number,
b: number,
) => void
readonly __wbindgen_free: (a: number, b: number, c: number) => void
readonly __wbindgen_exn_store: (a: number) => void
readonly wasm_bindgen__convert__closures__invoke2_mut__h8bdaa9faeb7d5075: (
a: number,
b: number,
c: number,
d: number,
) => void
}

export type SyncInitInput = BufferSource | WebAssembly.Module
/**
* Instantiates the given `module`, which can either be bytes or
* a precompiled `WebAssembly.Module`.
*
* @param {SyncInitInput} module
*
* @returns {InitOutput}
*/
export function initSync(module: SyncInitInput): InitOutput

/**
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
* for everything else, calls `WebAssembly.instantiate` directly.
*
* @param {InitInput | Promise<InitInput>} module_or_path
*
* @returns {Promise<InitOutput>}
*/
export default function __wbg_init(
module_or_path?: InitInput | Promise<InitInput>,
): Promise<InitOutput>
Loading

0 comments on commit ec6f0c2

Please sign in to comment.