Skip to content
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!: cryptosuite-style signers #801

Merged
merged 16 commits into from
Oct 31, 2023
Merged

refactor!: cryptosuite-style signers #801

merged 16 commits into from
Oct 31, 2023

Conversation

rflechtner
Copy link
Contributor

@rflechtner rflechtner commented Oct 18, 2023

fixes KILTProtocol/ticket#2962

Apparently nobody likes our present signer interfaces; they seem to be hard to wrap your head around.
Upcoming presentation signing with data integrity proofs means that a different sort of signer interface is required to produce those signatures, as the key identifier and algorithm is signed into the proof and thus must be known prior to signing, which does not work with our current callbacks (which return the key id together with the signature).

In order to avoid a proliferation of different signing interfaces in our sdk, this PR aims to migrate all signer functions to the interfaces introduced by our data integrity proof cryptosuites. This may actually also increase ergonomics, as it is implemented in a way that users can generate signers for their keys and DIDs once, and simply throw them all at a given function, which will select and call the appropriate handler.

TBD (possibly in a later PR)

  • Helper to create a signature using a DID and its signers
  • Signing did creation with the signers
  • Signing submittable extrinsic with a signer
  • Reusable logic for selecting a signer to be used with a did + error reporting
  • Use signers from external library after adjusting them to accept private keys

How to test:

This is WIP; ergonomics is important here, so writing some example signing flows would help a lot.

Checklist:

  • I have verified that the code works
  • I have verified that the code is easy to understand
    • If not, I have left a well-balanced amount of inline comments
  • I have left the code in a better state
  • I have documented the changes (where applicable)
    • Either PR or Ticket to update the Docs
    • Link the PR/Ticket here

@rflechtner rflechtner self-assigned this Oct 18, 2023
@rflechtner rflechtner changed the base branch from develop to vc-refactor October 18, 2023 14:52
@rflechtner rflechtner changed the base branch from vc-refactor to aa/native-did-attempt-2 October 19, 2023 19:00
@rflechtner rflechtner force-pushed the rf-signers branch 3 times, most recently from c92a0f9 to 04eb5b3 Compare October 23, 2023 16:05
@rflechtner rflechtner marked this pull request as ready for review October 24, 2023 05:56
@rflechtner rflechtner requested a review from ntn-x2 October 24, 2023 05:57
Copy link
Member

@ntn-x2 ntn-x2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general I like it! I see what you did there. I left some comments around naming and typing. It looks like there's mostly raw strings everywhere, and maybe we can change that to help TS developers a bit more? Or am I missing something?

packages/utils/src/Signers.ts Show resolved Hide resolved
packages/utils/src/Signers.ts Outdated Show resolved Hide resolved
packages/utils/src/Signers.ts Show resolved Hide resolved
packages/utils/src/Signers.ts Outdated Show resolved Hide resolved
packages/utils/src/Signers.ts Outdated Show resolved Hide resolved
packages/did/src/Did.chain.ts Outdated Show resolved Hide resolved
packages/types/src/Signers.ts Outdated Show resolved Hide resolved

export type SignerInterface = {
algorithm: string
id: string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, should the id be optional? For instance when signing an extrinsic, we don't really care about the ID of the key. We don't care about the algorithm either, but I guess we have it to rule out signatures that will definitely fail when submitted to the chain.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do care about the id even when signing extrinsics, because we need it to figure out which verification relationship a key is in. Even as an account signer we need to know for which account this signs. So I'd say the id is crucial, always

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I see. I guess I was referring to the case where the signer is an account, indeed. It kinda feels a bit of a stretch to use the account representing the key as the ID for that key. Let's see what the others have to say about it. Cc @lukeg90 @Dudleyneedham

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it could potentially be confusing for a developer to determine what string they should enter here as the ID, especially when signers can be both accounts and DIDs, depending on the context . But I don't really have a suggestion for improvement, other than making sure we have good documentation.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course if they always use the getSigner methods then they don't even have to care what the ID is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's the intended way for the signer to be created, indeed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah this would mostly get unnoticed; there may be a getAccountSigners function or method that creates all signers for an account (using Addresses as ids) and a getSigners method on a DID class or something that returns all signers for its verificationMethods (where all ids are DID URLs). This higher level api is TBD in a follow-up PR, but I see a lot of potential

packages/utils/src/Signers.ts Outdated Show resolved Hide resolved
Copy link
Member

@Dudleyneedham Dudleyneedham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I like the term signers however, I couldn't come up with anything interesting.

Looks good.

}
const verificationMethod = delegateDid.verificationMethod?.find(
({ id }) => id === fragment
const { byDid, verifiableOnChain } = Signers.select
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does byDid mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you select a Signer byDid (-> by it's association to a Did, via the DidDocument). I thought that was self-explanatory, how can this be improved?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think on its own it might not make sense, but when it's exported with a named object, it made more sense to me, also the way it's used in the tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any suggestions here?

packages/did/src/Did.chain.ts Outdated Show resolved Hide resolved
packages/did/src/DidDetails/FullDidDetails.ts Outdated Show resolved Hide resolved
packages/legacy-credentials/src/Credential.ts Show resolved Hide resolved
packages/utils/src/Signers.ts Show resolved Hide resolved
packages/utils/src/Signers.ts Show resolved Hide resolved
packages/utils/src/Signers.ts Outdated Show resolved Hide resolved
packages/utils/src/Signers.ts Outdated Show resolved Hide resolved
packages/utils/src/Signers.ts Outdated Show resolved Hide resolved
packages/utils/src/Signers.ts Show resolved Hide resolved
packages/utils/src/Signers.ts Outdated Show resolved Hide resolved
packages/utils/src/Signers.ts Show resolved Hide resolved
packages/utils/src/Signers.ts Outdated Show resolved Hide resolved
packages/utils/src/Signers.ts Outdated Show resolved Hide resolved
packages/utils/src/Signers.ts Show resolved Hide resolved
packages/did/src/DidDetails/FullDidDetails.ts Outdated Show resolved Hide resolved
packages/did/src/DidDetails/FullDidDetails.ts Outdated Show resolved Hide resolved
@lukeg90
Copy link

lukeg90 commented Oct 24, 2023

Good riddance signing callbacks!

Copy link
Member

@ntn-x2 ntn-x2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's few incompatibilities with the underlying DID refactoring branch by now (sorry about that). But as far as I am concerned, this could be merged. Looking forward for the rest of the issues by others to be resolved.

Base automatically changed from aa/native-did-attempt-2 to vc-refactor October 26, 2023 07:56
* allows removing reimplementation signer factories
* allows stronger typing of algorithm identifiers
@rflechtner rflechtner merged commit 88fb8c0 into vc-refactor Oct 31, 2023
11 of 14 checks passed
@rflechtner rflechtner deleted the rf-signers branch October 31, 2023 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants