Standalone

Stealth Addresses

close button

Part II

Generating Stealth Addresses

The Cursed Grimoires is an ERC721 collection that wishes to support stealth transfers between its users. To do so, it needs the following features:

  1. Users need to be able to declare their public keys. This allows others to use these keys to generate stealth addresses and discreetly send them tokens.

  2. The logic to compute stealth addresses off-chain should be provided.

  3. The ERC721 token has to log all stealth transfers. This allows recipients to search for any stealth transfers designated to them.

Hence, the CursedGrimoires contract wants to support the following interface.

Function

Description

print(recipient, tokenId)

Mints tokenId and transfers it to recipient.

register(publicKey)

Register the given public key to msg.sender. Reverts if the given public key does not belong to msg.sender.

stealthTransfer(stealthRecipient, tokenId, publishedDataX, publishedDataY)

Transfers a grimoire to a stealth address and emits a StealthTransfer event.

View Function

Description

getStealthAddress(recipientAddress, secret) → (stealthAddress, publishedData)

Generates a stealth address (and its published data) given a registered recipientAddress and an accompanying secret.

The detailed interface can be found in interfaces/IGrimoires.sol.

With this implemented interface, CursedGrimoires facilitates stealth transfers via the following process:

  1. Recipient calls register() to register their public key onto the contract.

  2. Sender calls getStealthAddress() off-chain to generate a stealth address belonging to the registered recipient.

    This must be done off-chain, or else everyone can see the recipient's true identity from the input parameters.

  3. Sender calls stealthTransfer() to transfer the token to the generated stealth address. This also logs relevant information for the recipient to compute the private key to the stealth address.

Your Task

Implement the CursedGrimoires contract using the Improved Stealth Address Protocol (ISAP) covered in the previous section.

Only make changes to the files listed in files-to-test.json! Do not add or modify any other files in the contracts/ folder.

Run tests in Questplay

Looking for a way to trade their literature discreetly, owners of the Cursed Grimoires come seeking both your aid and your… discretion.