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

Generalize userid authentication #2589

Draft
wants to merge 41 commits into
base: update-to-stream-registry-v5
Choose a base branch
from

Conversation

harbu
Copy link
Contributor

@harbu harbu commented Jun 13, 2024

Summary

Please provide a summary of the changes and a motivation if applicable.

Changes

Provide a bullet list of individual changes. Leave this section out if change
set is small and obvious from summary.

Limitations and future improvements

TODO

  • Change 4*randomUserId functions to use random length instead of Ethereum-compatible 20 bytes
  • Make a separate PR about removing legacy key support, can merge "immediately"
  • Move (branded) type UserID type from dht to trackerless-network
  • Grep address and userAddress and replace with e.g. userId in project.
  • Test function randomUserId() for tests
  • Is the userAddress field deprecated in The Graph? Should we use the userId field, or both?
  • Could we have a smart toEthereumAddress utility so that we wouldn't need isEthereumAddressByteArray function?

Checklist before requesting a review

  • Is this a breaking change? If it is, be clear in summary.
  • 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.

@github-actions github-actions bot added network Related to Network Package client Related to Client Package protocol Related to Protocol Package utils docs labels Jun 13, 2024
@harbu harbu force-pushed the generalize-userid-authentication branch from 3a65491 to 07d59dc Compare July 4, 2024 11:35
@github-actions github-actions bot added the sdk label Jul 4, 2024
@harbu harbu force-pushed the generalize-userid-authentication branch from 07d59dc to 3500245 Compare July 9, 2024 08:34
@harbu harbu force-pushed the generalize-userid-authentication branch 2 times, most recently from 64fdf85 to d3c7960 Compare August 6, 2024 07:43
@harbu harbu force-pushed the generalize-userid-authentication branch 3 times, most recently from a7b21f1 to 3050b54 Compare September 19, 2024 08:25
@@ -356,9 +358,9 @@ export class StreamRegistry {
if (isPublicPermissionQuery(query)) {
return this.streamRegistryContractReadonly.hasPublicPermission(streamId, permissionType)
} else if (query.allowPublic) {
return this.streamRegistryContractReadonly.hasPermission(streamId, toEthereumAddress(query.user), permissionType)
return this.streamRegistryContractReadonly.hasPermission(streamId, binaryToHex(query.user), permissionType)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

is binaryToHex needed?

} else {
return this.streamRegistryContractReadonly.hasDirectPermission(streamId, toEthereumAddress(query.user), permissionType)
return this.streamRegistryContractReadonly.hasDirectPermission(streamId, binaryToHex(query.user), permissionType)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

is binaryToHex needed?

try {
return await this.streamRegistryContractReadonly.hasPermission(streamId, userAddress, streamPermissionToSolidityType(StreamPermission.PUBLISH))
const permission = await this.streamRegistryContractReadonly.getPermissionsForUserId(streamId, userId)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consider renaming to

permissionsRecord

try {
return await this.streamRegistryContractReadonly.hasPermission(streamId, userAddress, streamPermissionToSolidityType(StreamPermission.SUBSCRIBE))
const permission = await this.streamRegistryContractReadonly.getPermissionsForUserId(streamId, userId)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consider renaming to

permissionsRecord

@@ -42,7 +42,7 @@ export class PublisherKeyExchange {
private readonly store: LocalGroupKeyStore
private readonly authentication: Authentication
private readonly logger: Logger
private readonly erc1271ContractAddresses = new Set<EthereumAddress>()
private readonly erc1271ContractAddresses = new ObjectSet<Uint8Array>((u) => binaryToHex(u, true))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Move back to Set<EthereumAddress>. Follow-up question: do we need ObjectSet at all?

@@ -40,7 +39,7 @@ export const PUBLIC_PERMISSION_ADDRESS = '0x000000000000000000000000000000000000

export type PermissionQueryResult = {
id: string
userAddress: EthereumAddress
userAddress: string
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should this be userId?

@harbu harbu force-pushed the generalize-userid-authentication branch 3 times, most recently from 373e508 to 6a89198 Compare September 19, 2024 12:21
@github-actions github-actions bot removed the docs label Sep 19, 2024
@github-actions github-actions bot removed the dht Related to DHT package label Sep 20, 2024
teogeb and others added 5 commits September 20, 2024 17:59
…unicator (#2737)

## Summary

Removed unused EventEmitter from the RpcCommunicator
## Background

In `jest` we can't use `toEqual` assertions for binary data. E.g. this
kind of assertion fails:
```
expect(new Uint8Array([1, 2, 3])).toEqual(Buffer.from([1, 2, 3]))
```

Typically test shouldn't care whether the data is stored in `Uint8Array`
or a `Buffer`. Therefore it would be ok to have that kind of assertion
in a test case.

## Changes

Added `toEqualBinary` jest custom matcher to `test-utils` package. This
allows us to add assertions about binary data like this:
```ts
expect(new Uint8Array([1, 2, 3])).toEqualBinary(new Uint8Array([4, 5, 6]))
```

If the assertion fails, it prints a readable error message:
```
Binaries are not equal

Expected: "0x040506"
Received: "0x010203"
```

## How to use

### Jest setup

```js
'@streamr/test-utils/setupCustomMatchers'
```

to `setupFilesAfterEnv` in `jest.config.js`

### Type information

```ts
import '@streamr/test-utils/customMatcherTypes'
```
e.g. to `test/types/global.d.ts`

### Karma setup (if needed)

```js
const { customMatchers } = require('@streamr/test-utils')
expect.extend(customMatchers)
```

to `karma-setup.js`

## Dependency update

- Bump `jest` from v29.5 to v29.7.

## Future improvements

- Maybe the error message could include more info, e.g.:
  - lengths of the inputs
  - the offset where the contents differ
  - UTF8 text representation of the data if it seems to be ASCII data
@github-actions github-actions bot added test-utils Related to Test Utils Package dht Related to DHT package proto-rpc labels Sep 23, 2024
@teogeb teogeb force-pushed the generalize-userid-authentication branch from 26a4d5b to 993f38e Compare September 23, 2024 20:35
@teogeb teogeb force-pushed the generalize-userid-authentication branch from bf75cef to 3010613 Compare September 23, 2024 22:36
@teogeb teogeb force-pushed the generalize-userid-authentication branch from 7fba5e1 to bb5da43 Compare September 24, 2024 13:30
This was referenced Sep 25, 2024
teogeb added a commit that referenced this pull request Sep 26, 2024
Added new helper type `UserID`, which is currently just an alias to
`EthereumAddress`. Replaced the `EthereumAddress` type with this new
type in all places where the address is a user id.

Also unified some variable/parameter names.

This is a preparation PR for
#2589, in which the `UserID`
type will be changed to `UInt8Array`.

## Other changes

Changed argument type of `StreamrClient#addEncryptionKey` from
`EthereumAddress` to `string` as the method is part of our public API.
teogeb added a commit that referenced this pull request Sep 26, 2024
Use random user id in tests. Changed the usages of
`randomEthereumAddress` to `randomUserId`, and in some cases changed
static user id to randomly generated user id.

This is a preparation PR for
#2589, in which the
`randomUserId()` will return a `UInt8Array`.
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 client Related to Client Package dht Related to DHT package network Related to Network Package node proto-rpc protocol Related to Protocol Package sdk test-utils Related to Test Utils Package utils
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants