diff --git a/package.json b/package.json index 34804fbd65..46b3f8d250 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,9 @@ "clients/validator", "sdk/typescript/packages/**", "sdk/typescript/examples/**", + "sdk/typescript/codegen/**", + "sdk/typescript/packages/**", + "sdk/typescript/examples/**", "sdk/typescript/codegen/**" ], "scripts": { diff --git a/sdk/typescript/examples/credentials/browser/src/index.ts b/sdk/typescript/examples/credentials/browser/src/index.ts index c0761fd42c..9b2ca8e369 100644 --- a/sdk/typescript/examples/credentials/browser/src/index.ts +++ b/sdk/typescript/examples/credentials/browser/src/index.ts @@ -5,6 +5,7 @@ async function main() { const mnemonic = document.getElementById('mnemonic') as HTMLInputElement; const coin = document.getElementById('coin') as HTMLInputElement; const button = document.getElementById('button') as HTMLButtonElement; + const client = await createNymCredentialsClient({ isSandbox: true }); // options: {isSandbox?: boolean; networkDetails?: {}} const generateCredential = async () => { diff --git a/sdk/typescript/packages/sdk/src/coconut/index.ts b/sdk/typescript/packages/sdk/src/coconut/index.ts index ba991d10d4..1d55504450 100644 --- a/sdk/typescript/packages/sdk/src/coconut/index.ts +++ b/sdk/typescript/packages/sdk/src/coconut/index.ts @@ -1,14 +1,6 @@ import * as Comlink from 'comlink'; import InlineWasmWebWorker from 'web-worker:./worker'; -import { - EventKinds, - CredentialClientOpts, - INymCredentialClientWebWorker, - NymCredentialsClient, -} from './types'; - -const mnemonic = - 'summer under connect sadness unveil region charge feed tank grant drift mass side ramp winter fit verb rare huge high garment moment achieve since'; +import { EventKinds, CredentialClientOpts, INymCredentialClientWebWorker, NymCredentialsClient } from './types'; export const createNymCredentialsClient = async (options?: CredentialClientOpts): Promise => { // eslint-disable-next-line @typescript-eslint/no-use-before-define @@ -18,28 +10,6 @@ export const createNymCredentialsClient = async (options?: CredentialClientOpts) const comlink = Comlink.wrap(worker); return { comlink }; - // pass the client interop and subscription manage back to the caller - // return { - // init(mnemonic) { // TODO: maybe? could also be passed in acquireCred - // comlink.setMnemonic(mnemonic); - // }, - // async acquireCredential(coin, mnemonic, options) { - // // TODO: wire up promise and event handlers - - // const handler = (msg: any) => { - // if (msg.data && msg.data.kind) { - // worker.removeEventListener('message', handler); - // return msg.data.credential; // return path in promise - // } - // worker.removeEventListener('message', handler); - // }; - - // worker.addEventListener('message', handler); - - // // fire message - // comlink.acquireCredential(coin); - // }, - // }; }; /** diff --git a/sdk/typescript/packages/sdk/src/coconut/worker.ts b/sdk/typescript/packages/sdk/src/coconut/worker.ts index bd55cbfa53..d162bcd50d 100644 --- a/sdk/typescript/packages/sdk/src/coconut/worker.ts +++ b/sdk/typescript/packages/sdk/src/coconut/worker.ts @@ -8,9 +8,9 @@ import * as Comlink from 'comlink'; // @ts-ignore // eslint-disable-next-line import/no-extraneous-dependencies import wasmBytes from '@nymproject/nym-credential-client-wasm/nym_credential_client_wasm_bg.wasm'; -import type { INymCredentialClientWebWorker, CredentialClientOpts } from './types'; -import { EventKinds, LoadedEvent } from './types'; import init, { acquireCredential } from '@nymproject/nym-credential-client-wasm/nym_credential_client_wasm'; +import type { INymCredentialClientWebWorker, CredentialClientOpts, LoadedEvent } from './types'; +import { EventKinds } from './types'; /** * Helper method to send typed messages. @@ -19,12 +19,19 @@ import init, { acquireCredential } from '@nymproject/nym-credential-client-wasm/ // eslint-disable-next-line no-restricted-globals const postMessageWithType = (event: E) => self.postMessage(event); -console.log('[Nym WASM client] Starting Nym WASM web worker...'); +console.log('[Nym WASM client for Credentials] Starting Nym WASM web worker...'); // load WASM binary async function main() { - const importResult = await init(wasmBytes()); - importResult.set_panic_hook(); + // rollup with provide a function to get the mixFetch WASM bytes + const bytes = await wasmBytes(); + + // load rust WASM package + const wasmPackage = await init(bytes); + + console.log('Loaded RUST WASM'); + + wasmPackage.set_panic_hook(); const webWorker: INymCredentialClientWebWorker = { async acquireCredential(coin: string, mnemonic: string, opts: CredentialClientOpts) { @@ -40,5 +47,4 @@ async function main() { postMessageWithType({ kind: EventKinds.Loaded, args: { loaded: true } }); } - -main(); \ No newline at end of file +main().catch((e: any) => console.error('Unhandled exception in credential worker', e));;