-
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
Change NodeId
from encoded string to an opaque alias of Id
which is a typed array from js-id
#318
Conversation
I think this PR will fix #261 as well. |
Are you going to create the PR on js-id too to include the additional static methods and instance methods for |
Are we still going to use a lambda and pass that around instead of passing the key manager to get the node id? I have a feeling that this isn't providing enough benefit to bother doing it. So I'm keeping how we are passing |
I suggest these encoding and decoding utilities to be put into function encodeNodeId(nodeId: NodeId): string {
return idUtils.toMultibase(nodeId, 'base32hex');
}
function decodeNodeId(nodeIdString: string): NodeId | undefined {
return idUtils.fromMultibase(nodeIdString) as NodeId | undefined;
} Where |
NodeId
type and fetchingNodeId
from encoded string to an opaque alias of Id
which is a typed array from js-id
Will need this merged for me to finish off #266. I'm already put the above functions in, but overall NodeId changes will be significant across the codebase. |
One annoying quirk of using const nodeIds: Record<NodeId, null>
for (const nodeId in nodeIds) {
// nodeId is a string here.
const newNodeId: NodeId = IdInternal.fromString(nodeId)!;
} |
That's to be expected. POJO keys are always strings. |
Is there any other database of nodes other than NodeGraph? Remember the node id should used as a buffer key during lookup. The gestalt graph should also be using the encoded NodeIds because they are likely to be shown to the end user in the GUI. |
I used I've run into the gestalt graph already, I'll have a deeper look at it at a later stage. |
Most of the changes are done.
The error is very peculiar
|
The Also is this PR rebased on master? It seems there are conflicting files. |
My mistake. Anything comparing two objects such as the
|
9f7f640
to
25ef555
Compare
Some problems with the sigChain that need sorting out. One small problem is that it expected strings for the |
Sigchain claims are JSON, so it will make sense to store them as encoded strings and not the original buffer. Unless of course there's an on-demand conversion when you read it out of the DB. But if the claims are stored as POJO values in the DB then storing it as an encoded string is fine.
On 24 January 2022 11:40:36 am AEDT, Brian Botha ***@***.***> wrote:
Some problems with the sigChain that need sorting out. One small problem is that it expected strings for the `NodeId` in the `ClaimData` and did some shortcuts with that POJO internally. This makes it a little tricky to neatly convert the `NodeId`s into strings internally. so for simplicity sake I'm going to have it use `NodeInEncoded` for the `NodeIds` instead.
--
Reply to this email directly or view it on GitHub:
#318 (comment)
You are receiving this because you commented.
Message ID: ***@***.***>
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
|
Most domains have been fixed up. currently failing test files are;
|
Just a reminder, if there are places where you need to decode an encoded node ID, and it may return undefined, but you know for sure that it won't return undefined because you created it or took it from a trusted source, like for example the database. Then you can just use We should however check for |
Did you remove the encoding/decoding functions from
|
Yes, they have been removed. |
I need to continue to review the usage of |
Barring any major that comes up in review. This should be ready to merge early tomorrow. |
MatrixAI/js-id#12 got merged and released as
|
What test failures are left to other PRs? Can you specify them in the PR description as well so we don't lose them @tegefaulkes. |
|
Fleshed out spec about how |
Tests that are not getting resolved here are; These were failing in the commit I branched off of.
relevant to the vaults domain.
Part of nodes and #310
|
9381241
to
fd6f6e5
Compare
fd6f6e5
to
733d540
Compare
Description
This PR will focus on applying the new
NodeId
which is an opaque alias ofId
(which itself is an alias ofIdInternal & number
).IdInternal
class, this requires a new PR injs-id
. IncludetoMultibase
andtoUUID
andtoBuffer
as instance methods, and thefromString
,fromMultibase
,fromUUID
, andfromBuffer
as static methods (these represent alternatives of creating theIdInternal
). Make sure that these functions returnId
as the type and notIdInternal
.NodeId
which is an opaque alias ofId
(which itself is an alias ofIdInternal & number
).NodeId
is expecting an encoded string. These will need to be changed to expect a sort oftype NodeIdEncoded = string;
, you still need anodesUtils.encodeNodeId
.NodeId
should be insidenodes/utils.ts
. This should be similar to how I'm doing it forVaultId
. An alternative might be to create class extension or generics, but this seems complicated.NodeId
will mostly occur inside the nodes domain, in particular theNodeGraph
can use theUint8Array
directly. Note that thejs-db
currently doesn't yet allow direct usage of theId
, because it requires aBuffer
type. However there is an issue UsebufferWrap
to supportArrayBuffer
,Uint8Array
andBuffer
js-db#3 to allow it to eventually takeId
, so for now, just useidUtils.toBuffer
andidUtils.fromBuffer
when interacting with the DB.NodeManager
toNodeConnectionManager
#310 on top to benefit from it.Issues Fixed
NodeId
as a proxy/singleton instance #254GenericIdTypes.ts
#299Tasks
IdInternal
class, this requires a new PR injs-id
. IncludetoMultibase
andtoUUID
andtoBuffer
as instance methods, and thefromString
,fromMultibase
,fromUUID
, andfromBuffer
as static methods (these represent alternatives of creating theIdInternal
). Make sure that these functions returnId
as the type and notIdInternal
. - Update to 3.2.0 of js-idNodeId
type to use an opaque alias ofId
.NodeId
to use the new type where possible.NodeId
is required, use aNodeIdEncoded
instead.KeyManager
and convert it from that.[ ]PolykeyAgent
should store theNodeId
. It should be updated via the event bus. ~ - stay with usingthis.keyManager.getNodeId()
.[ ] Anything that needs the NodeId should take a lambda that fetches it from the PolykeyAgent.- stick with injectingKeyManager
where it is neededNodeId
validation to RPC services and possibly bin commands.example of usage here.
#254 (comment)
Areas that need changes:
Status needs the string encoded to put into the status JSON file- Status file does indeed to use the encoded string, butStatusInfo
should still use theNodeId
and notNodeIdEncoded
because we want to do any validation on the boundary and ensure that our internal types in the context of the program uses types that imply that the validation occurred already, and therefore thenodeId
is indeed a valid node id.GestaltGraph.ts
needs to use the encoded string of the NodeId - its just because it is designed like this it's due to theGestaltKey
NodeInfo
for now has to useNodeIdEncoded
because it is being put into the database as a value as part of a POJO which gets JSON encoded. Plus thatGestaltGraph
andDiscovery
uses it as a string, but in the future it may be better done asNodeId
which follows the same reason as1.
about validation being done on the boundary.@tegefaulkes please flesh the above out.
Guidelines:
.toString()
Unresolved tests addressed in other PRs:
These were failing in the commit I branched off of. May be fix in #310 or #308
relevant to the vaults domain.
Part of nodes and #310
Final checklist