|
|
@ -124,45 +124,45 @@ export class Web3Accounts { |
|
|
|
eth_signTypedData_v4 (payload, cb) { |
|
|
|
eth_signTypedData_v4 (payload, cb) { |
|
|
|
const address: string = payload.params[0] |
|
|
|
const address: string = payload.params[0] |
|
|
|
const typedData: TypedMessage<MessageTypes> = payload.params[1] |
|
|
|
const typedData: TypedMessage<MessageTypes> = payload.params[1] |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
if (this.accounts[toChecksumAddress(address)] == null) { |
|
|
|
if (this.accounts[toChecksumAddress(address)] == null) { |
|
|
|
throw new Error("cannot sign data; no private key"); |
|
|
|
throw new Error("cannot sign data; no private key"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (typeof typedData === "string") { |
|
|
|
if (typeof typedData === "string") { |
|
|
|
throw new Error("cannot sign data; string sent, expected object"); |
|
|
|
throw new Error("cannot sign data; string sent, expected object"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!typedData.types) { |
|
|
|
if (!typedData.types) { |
|
|
|
throw new Error("cannot sign data; types missing"); |
|
|
|
throw new Error("cannot sign data; types missing"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!typedData.types.EIP712Domain) { |
|
|
|
if (!typedData.types.EIP712Domain) { |
|
|
|
throw new Error("cannot sign data; EIP712Domain definition missing"); |
|
|
|
throw new Error("cannot sign data; EIP712Domain definition missing"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!typedData.domain) { |
|
|
|
if (!typedData.domain) { |
|
|
|
throw new Error("cannot sign data; domain missing"); |
|
|
|
throw new Error("cannot sign data; domain missing"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!typedData.primaryType) { |
|
|
|
if (!typedData.primaryType) { |
|
|
|
throw new Error("cannot sign data; primaryType missing"); |
|
|
|
throw new Error("cannot sign data; primaryType missing"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!typedData.message) { |
|
|
|
if (!typedData.message) { |
|
|
|
throw new Error("cannot sign data; message missing"); |
|
|
|
throw new Error("cannot sign data; message missing"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const ret = signTypedData({ |
|
|
|
const ret = signTypedData({ |
|
|
|
privateKey: Buffer.from(this.accounts[toChecksumAddress(address)].privateKey), |
|
|
|
privateKey: Buffer.from(this.accounts[toChecksumAddress(address)].privateKey), |
|
|
|
data: typedData, |
|
|
|
data: typedData, |
|
|
|
version: SignTypedDataVersion.V4
|
|
|
|
version: SignTypedDataVersion.V4 |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
cb(null, ret) |
|
|
|
cb(null, ret) |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
cb(e.message) |
|
|
|
cb(e.message) |
|
|
|
}
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|