biscuit-auth / biscuit-wasm

WebAssembly wrapper for Biscuit authorization tokens
Apache License 2.0
24 stars 10 forks source link

ThirdPartyRequest.createBlock fails with a null pointer error #41

Open ishmam-mahmud opened 1 year ago

ishmam-mahmud commented 1 year ago

Running the following code:

// run.js
import { KeyPair, ThirdPartyRequest, block } from '@biscuit-auth/biscuit-wasm';

const third = new KeyPair()
const thirdBuilder = block`
 user(123);
`;

const thirdRequest = new ThirdPartyRequest();
const thirdBlock = thirdRequest.createBlock(third.getPrivateKey(), thirdBuilder)

returns the following error message:

(node:31428) ExperimentalWarning: Importing WebAssembly modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
biscuit-wasm loading
~/node_modules/@biscuit-auth/biscuit-wasm/module/biscuit_bg.js:2504
    throw new Error(getStringFromWasm0(arg0, arg1));
          ^

Error: null pointer passed to rust
    at __wbindgen_throw (~/node_modules/@biscuit-auth/biscuit-wasm/module/biscuit_bg.js:2504:11)
    at wasm://wasm/006425f6:wasm-function[1430]:0x122550
    at wasm://wasm/006425f6:wasm-function[1431]:0x12255d
    at wasm://wasm/006425f6:wasm-function[537]:0xd8538
    at ThirdPartyRequest.createBlock (~/node_modules/@biscuit-auth/biscuit-wasm/module/biscuit_bg.js:2104:18)
    at ~/run.js:10:33
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)

Line 2104:18 on biscuit_bg.js is

wasm.thirdpartyrequest_createBlock(retptr, ptr, private_key.ptr, block_builder.ptr);

and after adding some console.logs before that line, I found that ptr is undefined.

divarvel commented 1 year ago

The third-party request has to be created from a token. I'll check why the constructor is exposed, but it should not be used directly.

https://github.com/biscuit-auth/biscuit-wasm/blob/main/examples/node/index.js#L33-L41 shows how to append a third-party block to an existing token.