|
1 | | -## Running the Example |
| 1 | +# EIP-712 Signatures using Wrapped Keys |
2 | 2 |
|
3 | | -1. `yarn` |
4 | | -2. `cp .env.example .env` |
5 | | - - Fill in `ETHEREUM_PRIVATE_KEY` env with an account that has Lit test tokens on Yellowstone |
6 | | -3. `yarn test` |
| 3 | +This code example demonstrates how to sign an EIP-712 message using a Wrapped Key. |
7 | 4 |
|
8 | | -[test/index.spec.ts](./test/index.spec.ts) creates a EIP-712 message, serializes it, and then signs it using the Wrapped Keys SDK. However, when attempting to recover the address from the signed message, the address is not being recovered correctly because the `signTypedData` function is not being used within the Wrapped Key signing Lit Action. Instead `signMessage` is used which adds the following prefix to the message before signing: `0x19Ethereum Signed Message:\n${message.length}${message}`. |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- An Ethereum private key |
| 8 | + - This private key will be used to: |
| 9 | + - Mint a Lit Capacity Credit if none was specific in the project's `.env` file |
| 10 | + - In order to pay for this, the corresponding Ethereum account must have Lit Test Tokens. If you do not have any, you can get some from [the faucet](https://chronicle-yellowstone-faucet.getlit.dev/) |
| 11 | + - Create a Lit Capacity Credit delegation Auth Sig |
| 12 | +- This code example uses Node.js and Yarn please have these installed before running the example |
| 13 | + |
| 14 | +## Installation and Setup |
| 15 | + |
| 16 | +1. Clone the repository |
| 17 | +2. `cd` into the code example directory: `cd wrapped-keys/eip-712/nodejs` |
| 18 | +3. Install the dependencies: `yarn` |
| 19 | +4. Create and fill in the `.env` file: `cp .env.example .env` |
| 20 | + - `ETHEREUM_PRIVATE_KEY`: **Required** This is the Ethereum private key that will be used to mint a Lit Capacity Credit and create Lit Session Signatures |
| 21 | + - `CAPACITY_CREDIT_TOKEN_ID`: **Optional** This is the ID of the Lit Capacity Credit to use for the PKP delegation Auth Sig |
| 22 | + - `LIT_NETWORK`: **Optional** This is the Lit Network to use for the Lit Contracts and Lit Node Clients |
| 23 | + |
| 24 | +## Executing the Example |
| 25 | + |
| 26 | +1. Run `yarn test` to execute the examples-authentication.png) |
| 27 | + |
| 28 | +### Expected Output |
| 29 | + |
| 30 | +``` |
| 31 | + Signing an EIP-712 message using a Wrapped Key |
| 32 | +🔄 Generating EIP-712 message... |
| 33 | +✅ Generated and serialized EIP-712 message: {"domain":{"name":"Ether Mail","version":"1","chainId":1,"verifyingContract":"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"},"types":{"Person":[{"name":"name","type":"string"},{"name":"wallet","type":"address"}],"Mail":[{"name":"from","type":"Person"},{"name":"to","type":"Person"},{"name":"contents","type":"string"}]},"primaryType":"Mail","message":{"from":{"name":"Alice","wallet":"0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826"},"to":{"name":"Bob","wallet":"0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB"},"contents":"Hello, Bob!"}} |
| 34 | +🔄 Connecting LitNodeClient to Lit network... |
| 35 | +✅ Connected LitNodeClient to Lit network |
| 36 | +🔄 Connecting LitContracts client to network... |
| 37 | +✅ Connected LitContracts client to network |
| 38 | +🔄 Minting Capacity Credits NFT... |
| 39 | +✅ Minted new Capacity Credit with ID: 25144 |
| 40 | +🔄 Minting new PKP... |
| 41 | +✅ Minted new PKP with public key: 04cf95d05f3e237fef866f7daf169be4b773ced0cbcc2ce260b03b63026fc858ea182dabad3bdb37c49554527b92dbe53b260d3934dfde18e0fac8a03ccb10fe09 and ETH address: 0xC3bb43D840801959890A565bB58A0290fF0FE8Be |
| 42 | +🔄 Creating capacityDelegationAuthSig... |
| 43 | +✅ Created the capacityDelegationAuthSig |
| 44 | +🔄 Getting PKP Session Sigs... |
| 45 | +Storage key "lit-session-key" is missing. Not a problem. Contiune... |
| 46 | +Storage key "lit-wallet-sig" is missing. Not a problem. Continue... |
| 47 | +Unable to store walletSig in local storage. Not a problem. Continue... |
| 48 | +✅ Got PKP Session Sigs |
| 49 | +🔄 Generating wrapped key... |
| 50 | +✅ Generated wrapped key with id: 1133b4d5-2ffb-46c3-951d-0f0d7f4ccde2 and public key: 0x0402e173bf643ae623771b24cdda0ca01bec0409ca01d67f02090961c1394e81e1dd78c80fa3e116b0be032616d907f2775a4e9e1dc4cc08d19cbec0e51b1f83af |
| 51 | +🔄 Getting wrapped key metadata... |
| 52 | +✅ Got wrapped key metadata: { |
| 53 | + "ciphertext": "okHLOUDld4UJD+LaDz++3QVDngfm/mz9HNPDuOlnJHH/iiCPiDT2Adnn6odOuw2igW8g3cclh0PDwoZO97zdsEmCfQrs2UuUEzR844n/S01HmO7exNHAVRglrK9azstkShE+0/KcIWjG3I2x6BCX9OfvJcTDb/LX2okN5HxLDNZMNuNtdBK11GAkfqPoV28AoBpj/oYdnw4C", |
| 54 | + "dataToEncryptHash": "76f7ff2ae254f0771089216fe8413a768f189242fa1b406c3805edaf7c64dc13", |
| 55 | + "id": "1133b4d5-2ffb-46c3-951d-0f0d7f4ccde2", |
| 56 | + "keyType": "K256", |
| 57 | + "pkpAddress": "0xC3bb43D840801959890A565bB58A0290fF0FE8Be", |
| 58 | + "publicKey": "0x0402e173bf643ae623771b24cdda0ca01bec0409ca01d67f02090961c1394e81e1dd78c80fa3e116b0be032616d907f2775a4e9e1dc4cc08d19cbec0e51b1f83af", |
| 59 | + "litNetwork": "datil-test" |
| 60 | +} |
| 61 | +🔄 Signing EIP-712 message with Wrapped Key... |
| 62 | +✅ Signed EIP-712 message |
| 63 | +``` |
| 64 | + |
| 65 | +## Specific Files to Reference |
| 66 | + |
| 67 | +- [index.ts](./src/index.ts): Contains the code for: |
| 68 | + - Minting a PKP |
| 69 | + - Generating PKP Session Signatures |
| 70 | + - Generating a Wrapped Key |
| 71 | + - Getting the Wrapped Key metadata |
| 72 | + - Making the request to execute the Lit Action that signs an EIP-712 message using the Wrapped Key |
| 73 | +- [utils.ts](./src/utils.ts): Contains utility functions for the example |
| 74 | +- [wrappedKeyLitAction.ts](./src/wrappedKeyLitAction.ts): Contains the Lit Action code that signs an EIP-712 message |
| 75 | +- [index.spec.ts](./test/index.spec.ts): Contains the example EIP-712 message and test the example |
0 commit comments