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

feat(client) [NET-1269]: Add support for publishing on behalf of an ERC-1271 contract #2423

Merged
merged 65 commits into from
Mar 25, 2024

Conversation

harbu
Copy link
Contributor

@harbu harbu commented Mar 11, 2024

Summary

Add new signature type ERC_1271 that can be used to publish messages on behalf of a smart contract implementing ERC-1271.

Usage

const client = new StreamrClient({
  auth: {
    privateKey: '<REDACTED>'
  }
})

/* 
  Behind the scenes a call to contract method `isValidSignature` is performed to verify that 
  the client wallet address is a valid signer for the given contract.
*/
await client.publish('foobar.eth/hello/world', {
   key: 'value 
}, {
  erc1271contract: '0xc0ffee254729296a45a3885639AC7E10F9d54979' 
})

Misc changes

  • Fix fake timers behavior in browser test runner
  • Fix describe.each in browser test runner
  • Add signature type of MessageMetadata interface
  • Add groupKeyId to MessageMetadata interface
  • Revert commit where recoverSignature was removed from @streamr/utils exports. Add back unit tests too.
  • Move MapWithTtl to @streamr/utils. Add unit tests.

Limitations and future improvements

  • A symmetric feature would be being able to subscribe on behalf of an ERC-1271 contract. This will be implemented in an upcoming PR.
  • We could abstract different signature methods as sort of base interface and then implementations for each.
  • Instead of injecting instantiateContracts we could actually inject getStreamRegistryChainProviders to even more narrowly abstract the changing factor.

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.

Copy link

linear bot commented Mar 11, 2024

@github-actions github-actions bot added network Related to Network Package client Related to Client Package protocol Related to Protocol Package dht Related to DHT package utils labels Mar 11, 2024
Copy link
Contributor Author

@harbu harbu left a comment

Choose a reason for hiding this comment

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

Review with @teogeb , will address these

packages/client/src/contracts/ERC1271ContractFacade.ts Outdated Show resolved Hide resolved
packages/utils/src/signingUtils.ts Outdated Show resolved Hide resolved
packages/client/src/contracts/ERC1271ContractFacade.ts Outdated Show resolved Hide resolved
packages/client/src/contracts/ERC1271ContractFacade.ts Outdated Show resolved Hide resolved
packages/client/src/contracts/ERC1271ContractFacade.ts Outdated Show resolved Hide resolved
packages/client/src/signature.ts Outdated Show resolved Hide resolved
packages/client/src/utils/validateStreamMessage.ts Outdated Show resolved Hide resolved
packages/client/src/encryption/PublisherKeyExchange.ts Outdated Show resolved Hide resolved
@harbu harbu merged commit eadee3a into main Mar 25, 2024
23 checks passed
@harbu harbu deleted the NET-1269-signature-type-eip branch March 25, 2024 14:59
harbu added a commit that referenced this pull request Mar 28, 2024
## Summary
Subscribe on behalf of an ERC-1271 contract. Follow up to #2423 where we
implemented publishing on behalf of an ERC-1271 contract.

### Usage
```ts
const client = new StreamrClient({
    auth: {
        privateKey: '<REDACTED>'
    }
})

await client.subscribe({
    streamId,
    erc1271Contract: '0xc0ffee254729296a45a3885639AC7E10F9d54979'
}, (msg) => {
    console.log(msg)
})
```

---------

Co-authored-by: Teo Gebhard <teo@streamr.com>
fonty1 added a commit that referenced this pull request Jul 4, 2024
## Summary
Docs for Pub/sub on behalf of an ERC-1271
- #2423
- #2454

---------

Co-authored-by: Eric Andrews <harbu88@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client Related to Client Package dht Related to DHT package docs network Related to Network Package protocol Related to Protocol Package utils
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants