-
Notifications
You must be signed in to change notification settings - Fork 6
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
Feature/remote key manager #202
base: feature/p2pmessaging
Are you sure you want to change the base?
Conversation
…ation for deriveSharedSecret,decryptMessage methods
…remoteKeyManager, RemoteKeyHost, RemoteKeyClient
private selfIdClaim: any; | ||
private cruxProtocolMessenger: any; | ||
|
||
constructor(selfIdClaim: any, secureCruxNetwork: any, protocolSchema?: any) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't make sense to take protocolSchema as optional parameter. You always need protocol schema to be Key Management Protocol.
Is there any use case you designed this for? If not, remove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it does make sense I guess because CruxServiceClient can give you the different type of clients and some might use protocolSchema some might not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets add this when we add more use cases to CruxServiceClient. for now remove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove protocolSchema
from the constructor itself. Making it non optional doesn't help us. The point is that there is only 1 protocolSchema this class can be used with at the moment. does not make sense for caller to have to send it.
Just like in CruxWalletClient, the caller does NOT have any awareness of protocol schema or messenger internals or anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay i will remove it
src/infrastructure/implementations/blockstack-crux-user-repository.ts
Outdated
Show resolved
Hide resolved
let data; | ||
if (message.method === "signWebToken") { | ||
console.log("HandleMessage entrance:signWebToken"); | ||
data = await this.keyManager.signWebToken(message.args[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what will happen if function has multiple arguments? does args[0] mean only first argument will go?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all functions require single or zero parameters. So args[0] will work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better way to do it which will work for any function -
const func = (a, b) => {
console.log(a+b);
}
const args = [1,2]
// @ts-ignore
func(...args);
or
const func = (a, b) => {
console.log(a+b);
}
const args = [1,2]
func.apply(this, args);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
understood will modify it accordingly
Please fix merge conflicts carefully. There are some after I merged Sanchay's branch. |
@@ -98,7 +98,7 @@ export const getCruxUserRepository = (options: IBlockstackCruxUserRepositoryOpti | |||
|
|||
export const getPubsubClientFactory = (): IPubSubClientFactory => { | |||
return new CruxNetPubSubClientFactory({defaultLinkServer: { | |||
host: "broker.hivemq.com", | |||
host: "127.0.0.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't change this in code. In code we should have a globally accessible server.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shall we put it in config??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should ideally do it in the same way we've done it for Blockstack user repository. It also requires such a default for Blockstack stuff.
Look at line 127 of crux-wallet-client.ts
this.cruxBlockstackInfrastructure = options.blockstackInfrastructure || CruxSpec.blockstack.infrastructure;
Defaults are defined in CruxSpec
. just read directly from there. No need to do the options.blockstackInfrastructure ||
part.
@@ -71,7 +71,8 @@ export class RemoteKeyHost { | |||
console.log("Inside RemoteKeyHost::in::Msg, senderId: ", msg, senderId); | |||
const data = await this.handleMessage(msg); | |||
console.log("Inside RemoteKeyHost::initialize::Data(handleMessage): ", data); | |||
this.sendInvocationResult(data, senderId!); | |||
// @ts-ignore | |||
await this.sendInvocationResult(data, CruxId.fromString(senderId!)); // getting senderId as string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ID should be coming as object here. If it isn't then it's a bug! Can you fix it?
SecureReceiveSocket will be the right place to do it. Please think about why it's the right place to do it, let me know if you disagree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah seems so. will check it again and fix it. And yes SecureRecieveSocket will be best as it will make sure that it's consistent throughout (CruxID)
return this.makeRemoteMessageCall("deriveSharedSecret", [args]); | ||
} | ||
// @ts-ignore | ||
public decryptMessage = async (args: string) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong naming of parameter in all methods - look at other KeyManager implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry will take care of it
} | ||
// @ts-ignore | ||
public getPubKey = async () => { | ||
return this.makeRemoteMessageCall("getPubKey"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do an optimization here -
We know the Crux ID. And we're doing secure communication on the sole basis of the fact that we know the ID's Public Key. So we don't need to do makeRemoteMessageCall to getPubKey. You can get a CruxUser from CruxId and get Public Key from there. How to get CruxUser? We need UserRepository. SecureCruxNetwork already has a userRepository, Just that it's a private variable at the moment. You can make it public, and access it via CruxProtocolMessenger->SecureCruxNetwork->userRepository
public signWebToken = async (args: any) => { | ||
return this.makeRemoteMessageCall("signWebToken", [args]); | ||
} | ||
// @ts-ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove ts ignore and fix errors. Let me know if you're getting confused with 'args' and how to make it generic for arguments.
No description provided.