-
Notifications
You must be signed in to change notification settings - Fork 4
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
Refactor NodeId
as a proxy/singleton instance
#254
Comments
#312 has discussion about propagating changes of the key reset. Which has implications regarding how the NodeId is being acquired. |
Some notes about encoded form of the
When sortable base64 is available, we can switch to that for |
@tegefaulkes another important point is generation.
|
So the important function here is in
It looks like this has been changed to have This can be vastly simplified.
|
The reason the 16 byte limit is in the If UUID doesn't matter, then the 16 byte requirement can be dropped. What we could do is make All other conversion functions do not have a requirement to be 16 bytes. If we do this, we can update |
Subsequently this would mean that Thus when we want to use it as a string, we must first encode it. The encoding functions can take place inside |
New PR here MatrixAI/js-id#10 to address this for |
Released const fString = publicKeyToFingerprintBytes(publicKey);
const fTypedArray = forgeUtil.binary.raw.decode(fString);
const nodeId = Id.create(fTypedArray); |
Here's a demonstration on how it can work: import { util as forgeUtil } from 'node-forge';
import { IdInternal, utils as idUtils } from '@matrixai/id';
import * as keysUtils from './src/keys/utils';
async function main() {
const keyPair = await keysUtils.generateKeyPair(2048);
const fString = keysUtils.publicKeyToFingerprintBytes(keyPair.publicKey);
const fTypedArray = forgeUtil.binary.raw.decode(fString);
// This returns the type of `Id`, not type of `IdInternal`
const nodeId = IdInternal.create(fTypedArray);
console.log(nodeId);
const pojo = {
[nodeId]: 'hello world'
};
console.log(pojo[nodeId]);
const nodeIdEncoded = idUtils.toMultibase(nodeId, 'base32hex');
console.log(nodeIdEncoded);
console.log(idUtils.fromMultibase(nodeIdEncoded));
}
main(); Which outputs like this:
|
There's still the question of where node id is acquired. So far I like the idea of But the conversion to node id is something that should be in the nodes domain. There's some functionality that's sprawled out.
|
@tegefaulkes suggests that we can inject just a lambda that acquires the node id. That way you don't pass the key manager around, but you also don't pass a static node id around. You pass a lambda that must be called to acquire the node id when you need it. The lambda can be easily created as |
Ideas for refactoring #299 is a more general issue addressing the @tegefaulkes has some ideas regarding how to use generics for |
Specification
The node ID of a Polykey keynode is the public key fingerprint (based on the root keypair of the keynode). As such, on a key renewal/refresh, the node ID of the keynode will also change. Therefore, the node ID can be seen as dynamic state.
Currently we've had to be careful when we retrieve the node ID. We shouldn't be storing it as local, static state, otherwise this state needs to be updated when the root key changes.
The current solution has been to inject the
KeyManager
into any class where we require the node ID to be retrieved, such that we can callgetNodeId
to compute the node ID directly from the root key. This isn't the ideal solution: we shouldn't have to expose all of theKeyManager
whenever we need just the node ID.We should look into changing the node ID to be similar to the
Id
class injs-id
, or making use of thejs-permaproxy
library to do this (https://github.com/matrixai/js-permaproxy). Therefore, only the node ID's proxy instance would need to be injected where we need the node ID.Would we expose any other functionality other than a getter? If we wanted to do an "update" functionality, we'd actually need to perform an update on the root key itself (given that the node ID is derived from the public key). So perhaps instead, we could look into abstracting the root key as a proxy, such that a key update/renewal can be called without the
KeyManager
... this is potentially completely unnecessary though.Additional context
nodes
domain when injecting the node ID as a local, static property https://gitlab.com/MatrixAI/Engineering/Polykey/js-polykey/-/merge_requests/209#note_675531967KeyManager
#312 - Propagate keypair changes to other domainsGenericIdTypes.ts
#299 - NodeId applied to thejs-id
Tasks
The text was updated successfully, but these errors were encountered: