-
Notifications
You must be signed in to change notification settings - Fork 37
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
base: update-to-stream-registry-v5
Are you sure you want to change the base?
Generalize userid authentication #2589
Conversation
3a65491
to
07d59dc
Compare
07d59dc
to
3500245
Compare
64fdf85
to
d3c7960
Compare
a7b21f1
to
3050b54
Compare
@@ -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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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?
packages/sdk/src/permission.ts
Outdated
@@ -40,7 +39,7 @@ export const PUBLIC_PERMISSION_ADDRESS = '0x000000000000000000000000000000000000 | |||
|
|||
export type PermissionQueryResult = { | |||
id: string | |||
userAddress: EthereumAddress | |||
userAddress: string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be userId
?
373e508
to
6a89198
Compare
…ID from that package
…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
26a4d5b
to
993f38e
Compare
bf75cef
to
3010613
Compare
7fba5e1
to
bb5da43
Compare
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.
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`.
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
randomUserId
functions to use random length instead of Ethereum-compatible 20 bytestype UserID
type fromdht
totrackerless-network
address
anduserAddress
and replace with e.g.userId
in project.randomUserId()
for testsuserAddress
field deprecated in The Graph? Should we use theuserId
field, or both?toEthereumAddress
utility so that we wouldn't needisEthereumAddressByteArray
function?Checklist before requesting a review
TODO
comments left behind are meant to be left in.