TypeError: First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.
at fromObject (index.js:326)
at from (index.js:142)
at Function.Buffer.from (index.js:155)
at getPublicKeyFromPrivate (keys.js:41)
at signECDSA (encryption.js:210)
at GroupMembership._callee7$ (model.js:formatted:509)
at tryCatch (runtime.js:62)
at Generator.invoke [as _invoke] (runtime.js:288)
at Generator.prototype.(:3000/anonymous function) [as next] (webpack-internal:///./node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:114:21)
at asyncGeneratorStep (asyncToGenerator.js:3)
at _next (asyncToGenerator.js:25)
at eval (asyncToGenerator.js:32)
at new Promise (<anonymous>)
at GroupMembership.eval (asyncToGenerator.js:21)
at GroupMembership.sign (model.js:formatted:523)
at _callee3$ (model.js:formatted:308)
at tryCatch (runtime.js:62)
at Generator.invoke [as _invoke] (runtime.js:288)
at Generator.prototype.(:3000/anonymous function) [as next] (webpack-internal:///./node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:114:21)
at asyncGeneratorStep (asyncToGenerator.js:3)
at _next (asyncToGenerator.js:25)
at eval (asyncToGenerator.js:32)
at new Promise (<anonymous>)
at eval (asyncToGenerator.js:21)
at eval (model.js:formatted:344)
at new Promise (<anonymous>)
at GroupMembership._callee4$ (model.js:formatted:284)
at tryCatch (runtime.js:62)
at Generator.invoke [as _invoke] (runtime.js:288)
at Generator.prototype.(:3000/anonymous function) [as next] (webpack-internal:///./node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:114:21)
at asyncGeneratorStep (asyncToGenerator.js:3)
at _next (asyncToGenerator.js:25)
at eval (asyncToGenerator.js:32)
at new Promise (<anonymous>)
at GroupMembership.eval (asyncToGenerator.js:21)
at GroupMembership.save (model.js:formatted:358)
at GroupInvitation._callee$ (group-invitation.js:152)
at tryCatch (runtime.js:62)
at Generator.invoke [as _invoke] (runtime.js:288)
at Generator.prototype.(:3000/anonymous function) [as next] (webpack-internal:///./node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:114:21)
at asyncGeneratorStep (asyncToGenerator.js:3)
at _next (asyncToGenerator.js:25)
at eval (asyncToGenerator.js:32)
at new Promise (<anonymous>)
at GroupInvitation.eval (asyncToGenerator.js:21)
at GroupInvitation.activate (group-invitation.js:170)
at ActivateInvitation._callee$ (ActivateInvitation.jsx:29)
at tryCatch (runtime.js:62)
at Generator.invoke [as _invoke] (runtime.js:288)
at Generator.prototype.(:3000/anonymous function) [as next] (webpack-internal:///./node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:114:21)
I think you may have some issues with the way youāre writing asynchronous javascript. I may be mistaken, but the error is probably because the handlePendingSignIn() call is not finished before you call User.createWithCurrentUser().
Are you sure that the code snippet you provided is what is causing the error? The backtrace refers to GroupMembership, but that is nowhere in your code.
Also, Iāve just now published 0.1.6 of radiks, which contains some fixes to GroupMembership functionality. That may fix your issues. I meant to publish the npm version earlier this week, but it appears that I only published to Github, and not npm. Sorry about that! Upgrading may help your issue.
@hank
0.1.6 is the version that Iām working with. Iām doing the following
onst group = new UserGroup({ name: 'records-health-' + blockstack.loadUserData().profile.name });
console.log(group);
(async () => {
await group.create();
const invitation = await group.makeGroupMembership(this.state.usernameToInvite);
console.log(invitation._id); // the ID used to later activate an invitation
I think the name attribute of the UserGroup needs to be fixed ā i.e. should not include the userās name. The documentation for it doesnāt do that, for example. cc @hank
I donāt think the name of the group is a problem. However, what may be happening is that you canāt make an invitation for someone who hasnāt signed in to your app. The reason is because you arenāt able to know their public key in order to create the invitation. Is that the case?
I see. If you could possibly send me your code in itās current state, I can try debugging first thing in the morning. Itās hard for me to debug from these code samples, because I canāt see how the rest of the code is working. Iām hstove on Github or you can email me - {myfirstname}@blockstack.com . Iām sorry that youāre running into these issues!
Also, slightly off topic but Iām trying get my own private key so that I can decrypt files that have been encrypted with my public key. How can I do that?
FYI we had to pivot from the UserGroups stuff since we couldnāt get it to workāweāre using the get/put apiās now with additional logic.
ccing you guys now cause weāre on a time crunch now @hank@jude
Totally understood about the time crunch. Iām looking at the branch you made for me, and it looks like youāve already took out the Radiks-related code that hooks up to the UI. Iām not sure how you hooked that in before, but Iām not able to figure it out.
In Blockstack, you only have access to a userās app private key. We do not expose their āmasterā private key for security reasons. If you want to implement sharing functionality in your app, I recommend you do the following:
When user A logs in, get their app private key, and convert it to a public key using the blockstack.js getPublicKeyFromPrivate function.
Save this public key as something like publickey.txt, unencrypted.
When user B wants to share with user A, fetch publickey.txt from that user.
Encrypt user Bās health records with the public key of user A.
When user A wants to decrypt that shared file, they can just decrypt it with their app private key.
@hank I am facing the same issue but intermittently even after changing the code as you advised.
I think the function handlePendingSignIn() is throwing the error.
Can you further describe the error that is happening here? Can you be more specific about the exact user flow that causes this? Could you attach any backtraces?
What happens is that the user/developer can be working normally and signed in, may be working on some feature that is not related with signing into blockstack then the app stops getting the user data from blockstack.
Resetting the browser and creating new blockstack ids doesnāt work.
This issue happens intermittently.
if (!userSession.isUserSignedIn() && userSession.isSignInPending()) {
// the function handlePendingSignIn() returns the error:
// Uncaught (in promise) TypeError: First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object. */
const userData = await userSession.handlePendingSignIn();
if (!userData.username) {
throw new Error("This app requires a username");
}
}
This is whatās inside the GROUP_MEMBERSHIPS_STORAGE_KEY: