-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'injective-ledger' into release-v2.18.0
- Loading branch information
Showing
45 changed files
with
2,369 additions
and
1,134 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import _ from 'lodash' | ||
import { | ||
createWeb3Extension, | ||
createTxRawEIP712, | ||
getEip712TypedData | ||
} from '@injectivelabs/sdk-ts' | ||
import { | ||
BigNumberInBase, | ||
DEFAULT_BLOCK_TIMEOUT_HEIGHT | ||
} from '@injectivelabs/utils' | ||
import { SignMode } from "cosmjs-types/cosmos/tx/signing/v1beta1/signing.js"; | ||
|
||
import DefaultSigningAdapter from "./DefaultSigningAdapter.mjs"; | ||
|
||
export default class InjectiveSigningAdapter extends DefaultSigningAdapter { | ||
async sign(account, messages, memo, fee){ | ||
if(!this.signerProvider.isLedger()){ | ||
return super.sign(account, messages, memo, fee) | ||
} | ||
|
||
if(!this.signerProvider.signEIP712){ | ||
throw new Error('Unable to sign message with this wallet/signer') | ||
} | ||
|
||
const { chainId } = this.network | ||
const ethereumChainId = 1 | ||
const { account_number: accountNumber, sequence, address } = account | ||
|
||
const latestBlock = await this.network.restClient.getLatestBlock() | ||
const latestHeight = latestBlock.block.header.height | ||
const timeoutHeight = new BigNumberInBase(latestHeight).plus( | ||
DEFAULT_BLOCK_TIMEOUT_HEIGHT, | ||
) | ||
|
||
const injMessages = messages.map((m) => m.toInjective()) | ||
|
||
const eip712TypedData = getEip712TypedData({ | ||
msgs: injMessages, | ||
fee, | ||
tx: { | ||
memo: memo, | ||
accountNumber: accountNumber.toString(), | ||
sequence: sequence.toString(), | ||
timeoutHeight: timeoutHeight.toFixed(), | ||
chainId, | ||
}, | ||
ethereumChainId, | ||
}) | ||
|
||
const { signature, signed } = await this.signerProvider.signEIP712( | ||
chainId, | ||
address, | ||
eip712TypedData, | ||
{ | ||
chain_id: chainId, | ||
timeout_height: timeoutHeight.toFixed(), | ||
account_number: accountNumber.toString(), | ||
sequence: sequence.toString(), | ||
fee, | ||
msgs: injMessages.map((m) => m.toEip712()), | ||
memo: memo || '', | ||
} | ||
) | ||
|
||
const txRaw = { | ||
authInfoBytes: await this.makeAuthInfoBytes(account, { | ||
amount: signed.fee.amount, | ||
gasLimit: signed.fee.gas, | ||
}, SignMode.SIGN_MODE_LEGACY_AMINO_JSON), | ||
bodyBytes: this.makeBodyBytes(messages, signed.memo, timeoutHeight), | ||
} | ||
|
||
const web3Extension = createWeb3Extension({ | ||
ethereumChainId, | ||
}) | ||
const txRawEip712 = createTxRawEIP712(txRaw, web3Extension) | ||
|
||
const signatureBuff = Buffer.from( | ||
signature.signature, | ||
'base64', | ||
) | ||
txRawEip712.signatures = [signatureBuff] | ||
|
||
return txRawEip712 | ||
} | ||
|
||
pubkeyTypeUrl(pub_key){ | ||
if(pub_key && pub_key['@type']) return pub_key['@type'] | ||
|
||
return '/injective.crypto.v1beta1.ethsecp256k1.PubKey' | ||
} | ||
} |
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.