-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: eip712 verification against chain
- Loading branch information
1 parent
189cea3
commit 4fd66f7
Showing
46 changed files
with
291 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcWeb3GwApi.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import { AccountAddress, EthereumChainId } from '@injectivelabs/ts-types' | ||
import { | ||
DEFAULT_GAS_LIMIT, | ||
DEFAULT_BRIDGE_FEE_DENOM, | ||
DEFAULT_BRIDGE_FEE_PRICE, | ||
} from '@injectivelabs/utils' | ||
import { IndexerModule } from '../types' | ||
import { | ||
ErrorType, | ||
TransactionException, | ||
UnspecifiedErrorCode, | ||
} from '@injectivelabs/exceptions' | ||
import { InjectiveExchangeRpc } from '@injectivelabs/indexer-proto-ts' | ||
import { CosmosBaseV1Beta1Coin } from '@injectivelabs/core-proto-ts' | ||
import { IndexerGrpcTransactionApi } from './IndexerGrpcTransactionApi' | ||
|
||
/** | ||
* @category Indexer Grpc API | ||
*/ | ||
export class IndexerGrpcWeb3GwApi extends IndexerGrpcTransactionApi { | ||
protected module: string = IndexerModule.Web3Gw | ||
|
||
constructor(endpoint: string) { | ||
super(endpoint) | ||
} | ||
|
||
async prepareEip712Request({ | ||
address, | ||
chainId, | ||
message, | ||
memo, | ||
sequence, | ||
accountNumber, | ||
estimateGas = true, | ||
gasLimit = DEFAULT_GAS_LIMIT, | ||
feeDenom = DEFAULT_BRIDGE_FEE_DENOM, | ||
feePrice = DEFAULT_BRIDGE_FEE_PRICE, | ||
timeoutHeight, | ||
eip712Version = 'v1', | ||
}: { | ||
address: AccountAddress | ||
chainId: EthereumChainId | ||
message: any | ||
estimateGas?: boolean | ||
gasLimit?: number | ||
memo?: string | number | ||
timeoutHeight?: number | ||
feeDenom?: string | ||
feePrice?: string | ||
sequence?: number | ||
accountNumber?: number | ||
eip712Version?: string | ||
}) { | ||
const txFeeAmount = CosmosBaseV1Beta1Coin.Coin.create() | ||
txFeeAmount.denom = feeDenom | ||
txFeeAmount.amount = feePrice | ||
|
||
const cosmosTxFee = InjectiveExchangeRpc.CosmosTxFee.create() | ||
cosmosTxFee.price = [txFeeAmount] | ||
|
||
if (!estimateGas) { | ||
cosmosTxFee.gas = gasLimit.toString() | ||
} | ||
|
||
const prepareTxRequest = InjectiveExchangeRpc.PrepareEip712Request.create() | ||
prepareTxRequest.chainId = chainId.toString() | ||
prepareTxRequest.signerAddress = address | ||
prepareTxRequest.fee = cosmosTxFee | ||
|
||
const arrayOfMessages = Array.isArray(message) ? message : [message] | ||
const messagesList = arrayOfMessages.map((message) => | ||
Buffer.from(JSON.stringify(message), 'utf8'), | ||
) | ||
|
||
prepareTxRequest.msgs = messagesList | ||
|
||
if (timeoutHeight !== undefined) { | ||
prepareTxRequest.timeoutHeight = timeoutHeight.toString() | ||
} | ||
|
||
if (memo) { | ||
prepareTxRequest.memo = typeof memo === 'number' ? memo.toString() : memo | ||
} | ||
|
||
if (eip712Version) { | ||
prepareTxRequest.eip712Wrapper = eip712Version | ||
} | ||
|
||
if (accountNumber) { | ||
prepareTxRequest.accountNumber = accountNumber.toString() | ||
} | ||
|
||
if (sequence) { | ||
prepareTxRequest.sequence = sequence.toString() | ||
} | ||
|
||
try { | ||
const response = await this.client.PrepareEip712(prepareTxRequest) | ||
|
||
return response | ||
} catch (e: unknown) { | ||
if (e instanceof InjectiveExchangeRpc.GrpcWebError) { | ||
throw new TransactionException(new Error(e.toString()), { | ||
code: e.code, | ||
context: 'PrepareEip712', | ||
contextModule: 'Web3Gateway', | ||
type: e.type, | ||
}) | ||
} | ||
|
||
throw new TransactionException(e as Error, { | ||
code: UnspecifiedErrorCode, | ||
context: 'PrepareEip712', | ||
contextModule: 'Web3Gateway', | ||
type: ErrorType.Web3Gateway, | ||
}) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './modules' | ||
export * from './tx' | ||
export * from './accounts' | ||
export * from './utils' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.