Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update eth sig util #3802

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 51 additions & 47 deletions libs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions libs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@certusone/wormhole-sdk": "0.1.1",
"@ethersproject/solidity": "5.0.5",
"@improbable-eng/grpc-web-node-http-transport": "0.15.0",
"@metamask/eth-sig-util": "4.0.1",
"@project-serum/anchor": "0.24.1",
"@solana/spl-token": "0.1.8",
"@solana/web3.js": "1.37.1",
Expand All @@ -56,7 +57,6 @@
"cipher-base": "1.0.4",
"elliptic": "6.5.4",
"esm": "3.2.25",
"eth-sig-util": "2.5.4",
"ethereumjs-tx": "2.1.2",
"ethereumjs-util": "7.1.4",
"ethereumjs-wallet": "1.0.2",
Expand Down Expand Up @@ -94,7 +94,6 @@
"@types/async-retry": "1.4.4",
"@types/bn.js": "5.1.0",
"@types/bs58": "4.0.1",
"@types/eth-sig-util": "^2.1.1",
"@types/expect": "24.3.0",
"@types/form-data": "^2.5.0",
"@types/hashids": "2.0.1",
Expand Down
2 changes: 1 addition & 1 deletion libs/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const commonConfig = {
// * contain deps that need to be polyfilled via `nodePolyfills`
// * are ignored via `ignore`
const browserInternal = [
'eth-sig-util',
'@metamask/eth-sig-util',
'ethereumjs-tx',
'ethereumjs-util',
'ethereumjs-wallet',
Expand Down
27 changes: 14 additions & 13 deletions libs/src/data-contracts/signatureSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@
*/

import type {
EIP712Domain,
EIP712Message,
EIP712TypedData,
EIP712TypeProperty,
EIP712Types
} from 'eth-sig-util'
MessageTypeProperty,
MessageTypes,
TypedMessage
} from '@metamask/eth-sig-util'

type DomainFn = (chainId: number, contactAddress: string) => EIP712Domain
type DomainFn = (
chainId: number,
contactAddress: string
) => TypedMessage<MessageTypes>['domain']

function getDomainData(
contractName: string,
signatureVersion: string,
chainId: number,
contractAddress: string
): EIP712Domain {
): TypedMessage<MessageTypes>['domain'] {
return {
name: contractName,
version: signatureVersion,
Expand Down Expand Up @@ -307,18 +308,18 @@ export const schemas = {
manageEntity
}

type MessageSchema = readonly EIP712TypeProperty[]
type MessageSchema = MessageTypeProperty[]

function getRequestData(
domainDataFn: DomainFn,
chainId: number,
contractAddress: string,
messageTypeName: string,
messageSchema: MessageSchema,
message: EIP712Message
): EIP712TypedData {
message: TypedMessage<MessageTypes>['message']
): TypedMessage<MessageTypes> {
const domainData = domainDataFn(chainId, contractAddress)
const types: EIP712Types = {
const types: MessageTypes = {
EIP712Domain: schemas.domain
}
types[messageTypeName] = messageSchema
Expand Down Expand Up @@ -381,7 +382,7 @@ export type UserUpdateRequestFn = (
userId: number,
newValue: unknown,
nonce: string
) => EIP712TypedData
) => TypedMessage<MessageTypes>

const getUpdateUserMultihashRequestData: UserUpdateRequestFn = (
chainId,
Expand Down
16 changes: 8 additions & 8 deletions libs/src/services/dataContracts/IPLDBlacklistFactoryClient.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { ContractClient } from '../contracts/ContractClient'
import * as signatureSchemas from '../../data-contracts/signatureSchemas'
import sigUtil, { EIP712TypedData } from 'eth-sig-util'
import sigUtil, { SignTypedDataVersion } from '@metamask/eth-sig-util'
import { Buffer as SafeBuffer } from 'safe-buffer'
import type { Web3Manager } from '../web3Manager'
import type { MessageTypes, TypedMessage } from '@metamask/eth-sig-util'

type GeneratorFn = (
chainId: number,
contractAddress: string,
multihashDigest: string,
nonce: string
) => EIP712TypedData
) => TypedMessage<MessageTypes>['domain']

export class IPLDBlacklistFactoryClient extends ContractClient {
async addIPLDToBlacklist(multihashDigest: string, privateKey = null) {
Expand Down Expand Up @@ -59,12 +60,11 @@ export class IPLDBlacklistFactoryClient extends ContractClient {
)
let sig
if (privateKey) {
sig = sigUtil.signTypedData(
SafeBuffer.from(privateKey, 'hex') as unknown as Buffer,
{
data: signatureData
}
)
sig = sigUtil.signTypedData({
privateKey: SafeBuffer.from(privateKey, 'hex') as unknown as Buffer,
data: signatureData,
version: SignTypedDataVersion.V3
})
} else {
sig = await (this.web3Manager as Web3Manager).signTypedData(signatureData)
}
Expand Down
13 changes: 6 additions & 7 deletions libs/src/services/dataContracts/UserFactoryClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ContractClient } from '../contracts/ContractClient'
import * as signatureSchemas from '../../data-contracts/signatureSchemas'
import type { UserUpdateRequestFn } from '../../data-contracts/signatureSchemas'
import { Nullable, Utils } from '../../utils'
import sigUtil from 'eth-sig-util'
import sigUtil, { SignTypedDataVersion } from '@metamask/eth-sig-util'
import { Buffer as SafeBuffer } from 'safe-buffer'
import type { Web3Manager } from '../web3Manager'

Expand Down Expand Up @@ -311,12 +311,11 @@ export class UserFactoryClient extends ContractClient {
)
let sig
if (privateKey) {
sig = sigUtil.signTypedData(
SafeBuffer.from(privateKey, 'hex') as unknown as Buffer,
{
data: signatureData
}
)
sig = sigUtil.signTypedData({
privateKey: SafeBuffer.from(privateKey, 'hex') as unknown as Buffer,
data: signatureData,
version: SignTypedDataVersion.V3
})
} else {
sig = await this.web3Manager.signTypedData(signatureData)
}
Expand Down
4 changes: 4 additions & 0 deletions libs/src/services/dataContracts/UserLibraryFactoryClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export class UserLibraryFactoryClient extends ContractClient {
/* ------- SETTERS ------- */

async addTrackSave(userId: number, trackId: number) {
console.log('add track save')
const nonce = signatureSchemas.getNonce()
const chainId = await this.getEthNetId()
const contractAddress = await this.getAddress()
Expand All @@ -17,14 +18,17 @@ export class UserLibraryFactoryClient extends ContractClient {
trackId,
nonce
)
console.log({ signatureData })
const sig = await this.web3Manager.signTypedData(signatureData)
console.log({ sig })
const contractMethod = await this.getMethod(
'addTrackSave',
userId,
trackId,
nonce,
sig
)
console.log({ contractAddress, contractMethod })
return await this.web3Manager.sendTransaction(
contractMethod,
this.contractRegistryKey,
Expand Down
Loading