Skip to content

feat: [NET-1446] Quantum resistant identities and signatures - #3074

Merged
hpihkala merged 59 commits into
mainfrom
NET-1446/support-a-quantum-resistant-signature-algorithm
Apr 29, 2025
Merged

feat: [NET-1446] Quantum resistant identities and signatures#3074
hpihkala merged 59 commits into
mainfrom
NET-1446/support-a-quantum-resistant-signature-algorithm

Conversation

@hpihkala

@hpihkala hpihkala commented Apr 17, 2025

Copy link
Copy Markdown
Contributor

Summary

The goal of this PR is to add support for quantum secure cryptographic identities and signatures, as well as to make it easier to add more identity/signature types in the future. The PR includes some refactoring to create a new Identity abstraction which replaces the old Authentication interface.

Most of the line changes are due to renaming things + docs changes. The actual code changes in this PR are actually not that massive.

Changes

More significant changes:

  • Refactor old Authentication interface replaced by new Identity framework
  • Added support for ML-DSA-87 identity and signing
  • As an alternative to configuring keys, allow an Identity instance to be passed to StreamrClient as auth.identity
  • Add requireQuantumResistantSignatures and requireQuantumResistantEncryption config options as well as related checks
  • Add --public-key and --key-type options to CLI tool
  • Breaking change: In CLI tool, rename streamr wallet to streamr keys (the only command there was streamr wallet whoami, which is now streamr keys whoami. Add a new command streamr keys generate.
  • Breaking change: Removed StreamrClient.generateEthereumAccount(), the new way is EthereumKeyPairIdentity.generate() (can be done with other key/identity types as well).
  • Breaking change: The string values in Message.signatureType now correspond with the KeyType values. This means the previously output value SECP256K1 is now ECDSA_SECP256K1_EVM.
  • Large-ish docs changes

Additional minor changes:

  • Removed some technical debt from StreamMessageTranslator by removing oldContentType vs. newContentType, oldEncryptionType vs. newEncryptionType. The network-level enums are used directly now.
  • Give more accurate names to SignatureTypes, paving the road for more types to be added later.
  • Namespace the exports in signingUtils.ts by algorithm type, eg. ECDSA_SECP256K1_EVM and ML_DSA_87
  • Remove address as an acceptable parameter to key config
  • Add a central place identityConfig.ts for wiring together identities, SignatureTypes, and verification methods
  • Remove repetition / enumeration of SignatureTypes from Message.ts and SignatureValidator.ts
  • bugfix: Fix regex used for validating hex strings given to config

Limitations and future improvements

  • The client config key auth was kept as-is for backwards compatibility, although renaming it to identity would probably make sense at some point.
  • I didn't attempt to solve all overlap or inaccuracies in the docs (there are some). I mainly focused on the Identity article, the articles under the Security section, and any references to them.

Checklist before requesting a review

  • Is this a breaking change? If it is, be clear in summary. (no major breaking changes, but some exported supporting classes have changed)
  • Read through code myself one more time.
  • Make sure any and all TODO comments left behind are meant to be left in.
  • Has reasonable passing test coverage?
  • Updated changelog if applicable.
  • Updated documentation if applicable.

@linear

linear Bot commented Apr 17, 2025

Copy link
Copy Markdown

@github-actions github-actions Bot added network Related to Network Package cli-tools Related to CLI Tools Package dht Related to DHT package utils sdk node labels Apr 17, 2025
@hpihkala hpihkala changed the title feat: [NET-1446] Quantum resistant identities and signatures feat: [NET-1446] WIP Quantum resistant identities and signatures Apr 17, 2025

@teogeb teogeb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Second round of comments (utils, cli-tools, changelog)

Comment thread CHANGELOG.md Outdated
Comment thread packages/utils/src/signingUtils.ts
Comment thread packages/utils/src/signingUtils.ts Outdated
Comment thread packages/cli-tools/bin/streamr.ts Outdated

@teogeb teogeb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Third round of comments (most of the sdk)

Comment thread packages/sdk/src/Config.ts
Comment thread packages/sdk/src/Config.ts Outdated
Comment thread packages/sdk/src/Message.ts
Comment thread packages/sdk/src/identity/Identity.ts Outdated
Comment thread packages/sdk/src/identity/EthereumKeyPairIdentity.ts
Comment thread packages/sdk/src/identity/MLDSAKeyPairIdentity.ts Outdated
Comment thread packages/sdk/src/identity/identityConfig.ts
Comment thread packages/sdk/src/identity/identityConfig.ts Outdated
Comment thread packages/sdk/src/exports.ts Outdated

@teogeb teogeb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Rest of the comments about sdk.

Great improvements in this PR, with excellent readability 👍

Comment thread packages/sdk/src/identity/KeyPairIdentity.ts Outdated
Comment thread packages/cli-tools/bin/streamr-keys-whoami.ts Outdated
Comment thread packages/cli-tools/bin/streamr.ts Outdated
Comment thread packages/cli-tools/bin/streamr-keys-generate.ts Outdated
Comment thread packages/sdk/src/identity/EthereumKeyPairIdentity.ts
Comment thread packages/sdk/test/integration/quantum-policy.test.ts Outdated
Comment thread packages/sdk/test/integration/quantum-policy.test.ts Outdated
Comment thread packages/sdk/test/integration/quantum-policy.test.ts Outdated
Comment thread packages/sdk/test/integration/quantum-policy.test.ts Outdated
Comment thread packages/sdk/test/unit/validateStreamMessage2.test.ts Outdated

@teogeb teogeb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Some more comments

Comment thread packages/cli-tools/bin/streamr-identity-generate.ts Outdated
Comment thread packages/sdk/src/publish/MessageFactory.ts Outdated
Comment thread packages/sdk/src/utils/encryptionCompliance.ts Outdated
@teogeb
teogeb self-requested a review April 29, 2025 09:52

@teogeb teogeb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

@hpihkala
hpihkala merged commit d275b53 into main Apr 29, 2025
@hpihkala
hpihkala deleted the NET-1446/support-a-quantum-resistant-signature-algorithm branch April 29, 2025 13:40
hpihkala added a commit that referenced this pull request May 7, 2025
## Changes

- Add support for ECDSA on `secp256r1` curve. Uses webcrypto
(SubtleCrypto) for speed, as that's natively implemented in browsers.
- Had to refactor `createSignature` and `verifySignature` in
`SigningUtil` interface to be `async`, because webcrypto (SubtleCrypto)
only offers async methods.
- Offer an `assertValidKeyPair` utility function in all `SigningUtil`s
- The previous PR #3074 left some type safety holes in
`signingUtils.ts`, they are fixed here.
- Unify `EthereumKeyPairIdentity` constructor with other
`KeyPairIdentity` constructors. There's now a utility function
`EthereumKeyPairIdentity.fromPrivateKey(string)` for creating it from a
private key string.
- Moved `crossPlatformCrypto.ts` (utility to get `subtle`) from `sdk`
package to `utils` package, as it was needed there too.

## Checklist before requesting a review

- [x] Is this a breaking change? If it is, be clear in summary. **->
NO**
- [x] Read through code myself one more time.
- [x] Make sure any and all `TODO` comments left behind are meant to be
left in.
- [x] Has reasonable passing test coverage?
- [x] Updated changelog if applicable.
- [x] Updated documentation if applicable.
jtakalai pushed a commit that referenced this pull request May 20, 2025
## Summary

The goal of this PR is to add support for quantum secure cryptographic
identities and signatures, as well as to make it easier to add more
identity/signature types in the future. The PR includes some refactoring
to create a new `Identity` abstraction which replaces the old
`Authentication` interface.

Most of the line changes are due to renaming things + docs changes. The
actual code changes in this PR are actually not that massive.

## Changes

**More significant changes:**
- Refactor old `Authentication` interface replaced by new `Identity`
framework
- Added support for ML-DSA-87 identity and signing
- As an alternative to configuring keys, allow an `Identity` instance to
be passed to `StreamrClient` as `auth.identity`
- Add `requireQuantumResistantSignatures` and
`requireQuantumResistantEncryption` config options as well as related
checks
- Add `--public-key` and `--key-type` options to CLI tool
- **Breaking change**: In CLI tool, rename `streamr wallet` to `streamr
keys` (the only command there was `streamr wallet whoami`, which is now
`streamr keys whoami`. Add a new command `streamr keys generate`.
- **Breaking change**: Removed
`StreamrClient.generateEthereumAccount()`, the new way is
`EthereumKeyPairIdentity.generate()` (can be done with other
key/identity types as well).
- **Breaking change**: The string values in `Message.signatureType` now
correspond with the `KeyType` values. This means the previously output
value `SECP256K1` is now `ECDSA_SECP256K1_EVM`.
- Large-ish docs changes

**Additional minor changes:**
- Removed some technical debt from `StreamMessageTranslator` by removing
`oldContentType` vs. `newContentType`, `oldEncryptionType` vs.
`newEncryptionType`. The network-level enums are used directly now.
- Give more accurate names to `SignatureType`s, paving the road for more
types to be added later.
- Namespace the exports in `signingUtils.ts` by algorithm type, eg.
`ECDSA_SECP256K1_EVM` and `ML_DSA_87`
- Remove `address` as an acceptable parameter to key config
- Add a central place `identityConfig.ts` for wiring together
identities, `SignatureType`s, and verification methods
- Remove repetition / enumeration of SignatureTypes from `Message.ts`
and `SignatureValidator.ts`
- bugfix: Fix regex used for validating hex strings given to config

## Limitations and future improvements

- The client config key `auth` was kept as-is for backwards
compatibility, although renaming it to `identity` would probably make
sense at some point.
- I didn't attempt to solve all overlap or inaccuracies in the docs
(there are some). I mainly focused on the Identity article, the articles
under the Security section, and any references to them.

## Checklist before requesting a review

- [x] Is this a breaking change? If it is, be clear in summary. **(no
major breaking changes, but some exported supporting classes have
changed)**
- [x] Read through code myself one more time.
- [x] Make sure any and all `TODO` comments left behind are meant to be
left in.
- [x] Has reasonable passing test coverage?
- [x] Updated changelog if applicable.
- [x] Updated documentation if applicable.
jtakalai pushed a commit that referenced this pull request May 20, 2025
## Changes

- Add support for ECDSA on `secp256r1` curve. Uses webcrypto
(SubtleCrypto) for speed, as that's natively implemented in browsers.
- Had to refactor `createSignature` and `verifySignature` in
`SigningUtil` interface to be `async`, because webcrypto (SubtleCrypto)
only offers async methods.
- Offer an `assertValidKeyPair` utility function in all `SigningUtil`s
- The previous PR #3074 left some type safety holes in
`signingUtils.ts`, they are fixed here.
- Unify `EthereumKeyPairIdentity` constructor with other
`KeyPairIdentity` constructors. There's now a utility function
`EthereumKeyPairIdentity.fromPrivateKey(string)` for creating it from a
private key string.
- Moved `crossPlatformCrypto.ts` (utility to get `subtle`) from `sdk`
package to `utils` package, as it was needed there too.

## Checklist before requesting a review

- [x] Is this a breaking change? If it is, be clear in summary. **->
NO**
- [x] Read through code myself one more time.
- [x] Make sure any and all `TODO` comments left behind are meant to be
left in.
- [x] Has reasonable passing test coverage?
- [x] Updated changelog if applicable.
- [x] Updated documentation if applicable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli-tools Related to CLI Tools Package dht Related to DHT package docs network Related to Network Package node sdk utils

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants