Closed lastmjs closed 3 years ago
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.)
I just tried with your fork but I get the same issue
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
.
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!
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
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
I'm trying to run this code:
The
test
canister function looks like this in TypeScript:and would have this candid:
When I run the frontend code above, I keep getting this error:
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?