Skip to content

Can't sign the Voucher data in ethers.js via EIP712 #6

@b0b023

Description

@b0b023

I am trying to get the voucher data in ethers.js signed but was not successful to generate a valid signature yet.
I mainly followed this example: https://www.npmjs.com/package/ethers-eip712

What I am unsure about is the Voucher struct.
How does that have to represented?

At the moment I (unsuccessfully) tried this:

import { ethers } from 'ethers'
import { TypedDataUtils } from 'ethers-eip712'

const typedData = {
    "types": {
	"EIP712Domain": [
	    { "name": "name", "type": "string" },
	    { "name": "version", "type": "string" },
	    { "name": "chainId", "type": "uint256" },
	    { "name": "verifyingContract", "type": "address" }
	],
	"LazyNFTVoucher": [
	    {"name": "tokenId", "type": "uint256"},
	    {"name": "minPrice", "type": "uint256"},
	    {"name": "uri", "type": "string"}
	]
    },
    "primaryType": "LazyNFTVoucher",
    "domain": {
	"name": "LazyNFT",
	"version": "1",
	"chainId": 31337,
	"verifyingContract": "0x5fbdb2315678afecb367f032d93f642f64180aa3"
    },
    "message": {
	"tokenId" : "1337",
	"minPrice" : "1",
	"uri":"https://www.foo.bar"
    }
}
const digest = TypedDataUtils.encodeDigest(typedData)
const digestHex = ethers.utils.hexlify(digest)

const privateKey = '0xdf12089febbacf7ba0bc227dafbffa9fc08a93fdc68e1e42411a14efcf23656e'
var wallet = new ethers.Wallet(privateKey);

const signature = wallet.signMessage(digest)
var data = ethers.utils.hexlify( TypedDataUtils.encodeData(typedData, typedData.primaryType, typedData.message) )

The main reason why I want to use this is that I want to programmatically sign the vouchers - rather than using MetaMask

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions