Add ShieldNote.create factory for shield origination - #29
Merged
Merged
Conversation
bhflm
requested changes
Jul 23, 2026
Contributor
There was a problem hiding this comment.
Looks good overall, but I think this one needs a small fix before merge.
in src/notes/index.ts if we're exporting ShieldNoteParams here, should we also export ShieldNoteCreateParams?otherwise the new factory params type isn't available from the barrel export, right?
bhflm
approved these changes
Jul 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a static
ShieldNote.createfactory so integrators can construct a shield note for a recipient from their already-parsed master public key, instead of only reconstructing notes from scanned on-chain data.The factory takes
masterPublicKey, a full pre-feevalue, ERC20 or ERC721tokenData, and an optional 16-byterandom(generated via a browser-safe source when omitted). It derives the note public key through the existingNote.computeNotePublicKeypath and validates token data with the sharedassertValidNoteToken, so origination-side and scan-side commitment math and validation share one implementation. Inputs are validated up front: key and random lengths, supported token type, all-zerotokenSubIDfor ERC20, value of exactly 1 for ERC721, and a positive value within the contract's uint120 preimage bound. No fee math — the shield fee is deducted on-chain.Tests include fixed vectors derived with
@railgun-community/circomlibjsposeidon (andethereum-cryptographykeccak256 for the NFT token hash) asserting npk and both ERC20 and ERC721 commitment hashes match the reference implementation, msgpack serialize/deserialize round-trips, and per-rule validation rejections.deserializenow normalizes an absentblockNumbertoundefined(msgpack decodes missing fields asnull), matching the existingshieldFeehandling.Stacked on #28; retargets to
devonce that merges.