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: