-
Notifications
You must be signed in to change notification settings - Fork 23
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 packages APIs #301
Refactor packages APIs #301
Conversation
Codecov Report
@@ Coverage Diff @@
## monorepo #301 +/- ##
=============================================
+ Coverage 65.67% 88.25% +22.58%
=============================================
Files 48 33 -15
Lines 5223 2409 -2814
Branches 28 205 +177
=============================================
- Hits 3430 2126 -1304
+ Misses 1787 254 -1533
- Partials 6 29 +23
|
3d564b6
to
f21b9f1
Compare
c75113e
to
b4e1570
Compare
a0f1c49
to
d344181
Compare
d344181
to
d4a2d0c
Compare
d4a2d0c
to
ada6fda
Compare
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.
First pass. Looking good!
import { | ||
conditions, | ||
decrypt, | ||
encrypt, | ||
getPorterUri, | ||
initialize, | ||
ThresholdMessageKit, | ||
} from '@nucypher/taco'; |
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.
Look how shiny! 🤩
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.
It does look very clean 🎸
|
||
const privateKey = process.env.PRIVATE_KEY; | ||
if (!privateKey) { | ||
throw new Error('PRIVATE_KEY is not set.'); |
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.
We have a hardcoded example key for Enrico in nucypher
. See https://github.com/nucypher/nucypher/blob/4b978025a262f240a9afb9869257c070a33d767d/tests/constants.py#L88
Maybe we can use this here as a fallback?
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.
On one hand, it makes sense - This Enrico is already configured on testnet (allow-listed and so on) but on the other hand, I'm not sure what happens when a number of users start testing their apps with this default character.
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.
I don't think we have much of a choice for tapir
🤔 , unless:
- we make ritual initiation public (for say tapir)
- grant initiator roles to those who ask
only specific Enricos would be allowed (global allow list) to encrypt for rituals.
If neither 1 or 2 are feasible, at the very least we can probably provide more than one test authorized Enrico account private key.
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.
Decided to not pursue this change in the PR, tracking it here: #313
); | ||
|
||
console.log('Decrypting message...'); | ||
const porterUri = getPorterUri('lynx'); // Test network |
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.
How about we create some constants somewhere like TacoNetwork.DEV_TESTNET = 'lynx'
and TacoNetwork.TESTNET = 'tapir'
, and we reduce a bit the cognitive load for adopters? After all, how necessary is that adopters know that the testnet is called lynx/tapir?
Thoughts? @piotr-roslaniec @KPrasch @derekpierre
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.
It's another level of abstraction above domains which at this level of public exposure makes sense to me! 👍🏻
I suggest that we adopt the nucypher/nucypher convention to call these "domains" instead of "networks" for accuracy (although imperfect since it's another layer):
TacoDomain.DEV; TacoDomain.TEST
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.
I agree with both suggestions, tracking it in #311
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.
Agreed 👍
@@ -1,1375 +1,1423 @@ | |||
[ |
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.
Opened #310 to use our NPM package instead of manually tracking here. The NPM package probably needs updating, though (cc @manumonti)
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.
Nice - this thought crossed my mind as well.
@@ -13,7 +13,7 @@ const POLYGON: Contracts = { | |||
|
|||
const MUMBAI: Contracts = { | |||
SUBSCRIPTION_MANAGER: '0xb9015d7b35ce7c81dde38ef7136baa3b1044f313', | |||
COORDINATOR: '0x0f019Ade1D34399D946CF2f161386362655Dd1A4', | |||
COORDINATOR: '0x8E49989F9D3aD89c8ab0de21FbA2E00C67ca872F', |
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.
Opened #310. The bulk of this module should be externalized to the NPM package. See also
nucypher/nucypher-contracts#124 for on-going discussion
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.
It's so refreshing to see the demos so buttoned up and organized. 🤠
- [`nucypher-ts-demo`](https://github.com/nucypher/nucypher-ts-demo) - A demo of PRE in the `nucypher-ts` library. | ||
- [`tdec-sandbox`](https://github.com/nucypher/tdec-sandbox) - A demo of tDec in the `nucypher-ts` library. | ||
- [`tdec-nft-example`](https://github.com/nucypher/tdec-nft-example) - A demo of tDec in the `nucypher-ts` library. |
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.
In the spirit of the monorepo, shall we also internalize these demos to this repo?
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.
Internalizing nucypher-ts-demo
will require releasing @nucypher/pre
, which I think we should postpone. tdec-sandbox
and tdec-nft-example
will be deprecated (archived) and replaced by existing demos
.
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.
I also generally agree with the division of examples/demos mentioned above 👍🏻
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.
tdec-sandbox and tdec-nft-example will be deprecated (archived) and replaced by existing demos.
^ If we are going to deprecate/archive these, should we remove these in the readme then?
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.
I will remove them from the README.md
when we have a working alternative.
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.
These things are easy to forget. If you are going to leave them for now, I'd recommend filing an issue and setting the appropriate project on it, so that it can be followed up on.
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.
Tracked in #308
### Polygon | ||
|
||
`@nucypher/taco` is in an early release. We recommend **not** using it in | ||
production _just yet_. |
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.
Do we need this for a demo readme?
demos/taco-demo/src/App.tsx
Outdated
await switchNetwork(Mumbai.chainId); | ||
|
||
const provider = new ethers.providers.Web3Provider(window.ethereum); | ||
const ritualId = 2; // Replace with your own ritual ID |
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 it possible to make this some sort of UI input, or browser var or some variable that users can easily set somewhere eg. some kind of .env file equivalent for local scripts? Even if localized to a specific file.
Whatever process for updating this number should end up in the readme/demo instructions.
### Polygon | ||
|
||
`@nucypher/taco` is in an early release. We recommend **not** using it in | ||
production _just yet_. |
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.
Same question as in the other demo.
enabled, | ||
}: Props) => { | ||
const { library } = useEthers(); | ||
const goerliNFTAddress = '0x932Ca55B9Ef0b3094E8Fa82435b3b4c50d713043'; // https://goerli-nfts.vercel.app/ |
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.
Tapir is going to use sepolia (lynx will still use goerli) - so we'll need a new NFT address on sepolia.
They both will still use Mumbai, so if using an NFT on mumbai is simpler then that works too.
(cc @KPrasch )
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.
I guess we can keep this one around for use with Lynx, but yeah a new NFT contract on Sepolia will be needed, or as @derekpierre mentioned, just switch to a mumbai condition.
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.
I will update the demos when we release TACo on Sepolia. I always have to test them in cases like this anyway.
const messageKit = await encrypt(provider, message, hasPositiveBalance, ritualId, signer); | ||
|
||
console.log('Decrypting message...'); | ||
const porterUri = getPorterUri('lynx'); // Test network | ||
const decryptedMessage = await decrypt(provider, messageKit, signer, porterUri); |
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.
These API calls look great!
value: 0, | ||
}, | ||
}); | ||
const ritualId = 2; // Replace with your own ritual ID |
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.
Similar question about making this some sort of UI input/variable
@@ -1,1375 +1,1423 @@ | |||
[ |
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.
Nice - this thought crossed my mind as well.
packages/shared/src/contracts/ethers-typechain/factories/Coordinator__factory.ts
Show resolved
Hide resolved
@@ -11,7 +11,9 @@ export const rpcConditionSchema = z.object({ | |||
conditionType: z.literal(RpcConditionType).default(RpcConditionType), | |||
chain: createUnionSchema(SUPPORTED_CHAIN_IDS), | |||
method: z.enum(['eth_getBalance', 'balanceOf']), | |||
parameters: z.array(EthAddressOrUserAddressSchema), | |||
parameters: z.array( | |||
z.union([EthAddressOrUserAddressSchema, z.string(), z.number()]), |
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.
Why not just EthAddressOrUserAddressSchema
? Why also number or string?
PS. love how that typing reads.
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.
The second parameter to eth_getBalance
is blockNumer
, which is a string (as per JSON RPC schema). I thought that accepting a number here would be more intuitive. Does that make sense? Or should we expose strict interfaces (lifted straight from JSON RPC)?
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.
Oh right I got you.
But then we ideally want something like:
parameters = (EthAddressOrUserAddressSchema) OR (EthAddressOrUserAddressSchema, Union[string, int]])
So something like the following then (my zod is bad)?
z.array(
z.union([
EthAddressOrUserAddressSchema,
z.array(
EthAddressOrUserAddressSchema,
z.union([
z.string(),
z.number()]
])
)
])
)
If the above is the simplest way (perhaps not), might be cleaner to define a custom schema type somewhere else, similar to how we did EthAddressOrUserAddressSchema
.
We should test this if we aren't already.
packages/taco/src/taco.ts
Outdated
authSigner, | ||
); | ||
|
||
const isAuthorized = DkgCoordinatorAgent.isEncryptionAuthorized( |
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.
I think this check should be optional, and not done by default.
In some/most cases it is ok for Enrico to encrypt before being authorized. Authorization can be granted after encryption and the authorization check only really applies at decryption time (this was a prior question from BqEth).
I get the notion of being proactive about authorization before encryption, but they are different in their timing.
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.
Indeed, it's use-case specific, ritual-specific, and may actually be performed by different actors or user stories altogether.
Co-authored-by: David Núñez <david@nucypher.com>
Co-authored-by: David Núñez <david@nucypher.com>
Co-authored-by: Derek Pierre <derek.pierre@gmail.com>
1f30886
to
acb0fa1
Compare
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.
I reviewed code and ran the demo locally. Worked like a charm. Awesome work, Piotr! We're almost there
parameters: z.union([ | ||
z.array(EthAddressOrUserAddressSchema).length(1), | ||
// Using tuple here because ordering matters | ||
z.tuple([EthAddressOrUserAddressSchema, z.union([z.string(), z.number()])]), |
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.
Great - 🚀
@@ -34,4 +35,52 @@ describe('validation', () => { | |||
}, | |||
}); | |||
}); | |||
|
|||
describe('parameters', () => { |
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.
Love the testing!
Type of PR:
Required reviews:
Issues fixed/closed:
What this does:
@nucypher/nucypher-core
taco
packageIn theNot a prioritypre
packagetaco
for compatibility withdkg-alpha-13
, includingexamples
demos/taco-demo
Notes for reviewers:
@nucypher/taco
#308