[JS] @dfinity/agent version 0.7.1

Since 0.7.1 and agent at 0.9.1 I haven’t had any issues.

hmm ok, I am on dfx 0.7.1 and agent 0.9.1, but it’s throwing at:

Uncaught ReferenceError: Buffer is not defined
    at Principal.toText (index.ts:80)
    at Function.fromText (index.ts:49)
    at new CanisterActor (actor.ts:244)
    at Function.createActor (actor.ts:269)

I’ll try to polyfill buffer, see if it solves the issue.

Thanks for the quick response

-edit- fixed by polyfilling Buffer with: GitHub - feross/buffer: The buffer module from node.js, for the browser.

Yes, while I’m working on removing Buffer (and hopefully a few other Node.js features), it’s still a long-term work in progress and a pretty significant refactor. I’ll definitely make an announcement once it’s done

2 Likes

Could you share the polyfill code?

npm install buffer
import Buffer from "buffer/";
1 Like

If there’s a way to replace the BLS signature validation wasm code with performant JS instead, that’d be good too. Unfortunately, native mobile doesn’t seem to be able to run wasm (at least from what I can tell).

And when I convert the wasm to JS using binaryen’s wasm2js tool, it’s wayyyy too slow. For now, I comment out the BLS signature validation check entirely but for security’s sake I don’t want to…

@chenyan actually implemented the BLS signature validation in JS and it was not very performant there either. He suggested that the path forward would be to offload the BLS check to run in a canister so you can simply call out to verify it instead of shipping the wasm with agent-js.

We haven’t scoped out that work yet, though

1 Like

Hello
I have the same problem using variants in typescript.
How do you guys solve this?

I’ve started using the pattern

if("ok" in result){
  console.log(result.ok);
}

@kpeacock Hello!

Are there any chances to improve typescript support for variants?

I mean currently variants in typescript looks something like this:

type MyVariant = { "ok" : null } | { "err" : "myErrorCode"  }

It is hard to create predicate with such type union.

I think it would be great to have:

type Type_1 = { "ok" : null }
type Type_2 = { "err" : "myErrorCode" }
type MyVariant = Type_1 | Type_2

If we have names type - it has great predicate support.

Maybe it is worth to create separate thread for this…

2 Likes

Yeah, a separate thread would be good