Skip to content

Add ShieldNote.create factory for shield origination - #29

Merged
mattgle merged 3 commits into
devfrom
feat/shield-note-create
Jul 24, 2026
Merged

mattgle merged 3 commits into
devfrom
feat/shield-note-create

Conversation

@mattgle

@mattgle mattgle commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Adds a static ShieldNote.create factory 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-fee value, ERC20 or ERC721 tokenData, and an optional 16-byte random (generated via a browser-safe source when omitted). It derives the note public key through the existing Note.computeNotePublicKey path and validates token data with the shared assertValidNoteToken, 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-zero tokenSubID for 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/circomlibjs poseidon (and ethereum-cryptography keccak256 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. deserialize now normalizes an absent blockNumber to undefined (msgpack decodes missing fields as null), matching the existing shieldFee handling.

Stacked on #28; retargets to dev once that merges.

@mattgle mattgle self-assigned this Jul 23, 2026
@mattgle
mattgle requested a review from bhflm July 23, 2026 14:57
@mattgle
mattgle marked this pull request as ready for review July 23, 2026 14:57

@bhflm bhflm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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?

Comment thread src/notes/shield-note.ts
Base automatically changed from feat/shield-request-builder to dev July 23, 2026 20:27
@mattgle
mattgle requested a review from bhflm July 23, 2026 20:39
@mattgle
mattgle merged commit 48f51e0 into dev Jul 24, 2026
1 check passed
@mattgle
mattgle deleted the feat/shield-note-create branch July 24, 2026 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants