Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: "list" argument must be an Array of Buffers #5

Closed
lastmjs opened this issue Nov 1, 2021 · 6 comments · May be fixed by #6
Closed

TypeError: "list" argument must be an Array of Buffers #5

lastmjs opened this issue Nov 1, 2021 · 6 comments · May be fixed by #6

Comments

@lastmjs
Copy link

lastmjs commented Nov 1, 2021

I'm trying to run this code:

        const identity = await StoicIdentity.connect();

        const idlFactory = ({ IDL }) => {
            return IDL.Service({
                'test': IDL.Func([IDL.Text], [IDL.Text], ['query'])
            });
        };
    
        const agent = new HttpAgent({
            identity
        });
    
        const actor = Actor.createActor(idlFactory, {
            agent,
            canisterId: 'rrkah-fqaaa-aaaaa-aaaaq-cai'
        });
        
        console.log('result', await actor.test('hello'));

The test canister function looks like this in TypeScript:

export function test(message: string): Query<string> {
    return message;
}

and would have this candid:

    "test": (text) -> (text) query;

When I run the frontend code above, I keep getting this error:

Uncaught (in promise) TypeError: "list" argument must be an Array of Buffers
    at Function.concat (actor-1a9b5abd.js:5665)
    at ic-stoic-identity.js:11532

Everything executes just fine up to await actor.test('hello'), and somewhere during resolving actor.test the error is thrown. I've been trying a couple different combinations of canister methods and parameters and I'm not yet tracking down why this is happening.

For some more information, it seems to be here in the source code where the error is being thrown: https://github.com/Toniq-Labs/stoic-identity/blob/main/src/index.js#L86

Any pointers?

@electrovir
Copy link

electrovir commented Nov 1, 2021

I noticed some type errors like this when I was rewriting stoic-identity in TypeScript. You could try out my fork with the ic-stoic-identity-1634785846.tgz asset link here: https://github.com/electrovir/stoic-identity/releases

IIRC the type errors I found were centered around de-serializing the local storage data. (It's hard to know for certain where I changed actual logic though cause the git diff is useless since I basically rewrote the whole index.js file to add types.)

@lastmjs
Copy link
Author

lastmjs commented Nov 1, 2021

I just tried with your fork but I get the same issue

@lastmjs
Copy link
Author

lastmjs commented Nov 1, 2021

I think I figured it out, though it is very surprising that stoic-identity works at all if this is the case. Perhaps there has been a browser or dependency update that is causing this on my machine.

This line needs to be changed: https://github.com/Toniq-Labs/stoic-identity/blob/main/src/index.js#L86

Original:

const result = JSON.parse(await this.sign(Buffer.from(Buffer.concat([domainSeparator, new Uint8Array(requestId)]))));

Fixed:

const result = JSON.parse(await this.sign(Buffer.from(Buffer.concat([domainSeparator, Buffer.from(new Uint8Array(requestId))]))));

new Uint8Array(requestId) has been wrapped with Buffer.from.

@stephenandrews
Copy link
Contributor

Nice find! I think it's because the type error is just ignored, but concat handles it OK anyway. Definitely worth the fix tho, thanks so much!

@tommygames
Copy link

tommygames commented Jan 6, 2023

We're also getting this error when integrating Stoic and trying to make a call with the identity:

TypeError: "list" argument must be an Array of Buffers

Our code looks like this:

        const identity = await StoicIdentity.connect();

        const authCanisterId = 'zxrmm-bqaaa-aaaai-abn6q-cai'

        const idlFactory = ({IDL}) => {
            return IDL.Service({
                'get_auth_token': IDL.Func([], [IDL.Text], [])
            });
        };

        const agent = new HttpAgent({
            identity: identity,
            host: "https://ic0.app/",
        });

        const actor = Actor.createActor(idlFactory, {
            agent,
            canisterId: authCanisterId,
        });

        const token = await actor.get_auth_token();

The code works with all other IC wallets, only having this issue with Stoic

@tommygames
Copy link

It turns out my issue was exactly the same as @lastmjs :)

I thought that the fix already existed in the npm package.

I was able to patch the code locally, but would be good to update the ic-stoic-identity npm package with the fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants