-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add method support get-starknet (#173)
- Loading branch information
1 parent
9f1c593
commit a857eed
Showing
15 changed files
with
713 additions
and
116 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { toJson } from './utils/serializer'; | ||
import { Signature } from 'starknet'; | ||
import { ApiParams, SignDeclareTransactionRequestParams } from './types/snapApi'; | ||
import { getKeysFromAddress, signDeclareTransaction as signDeclareTransactionUtil } from './utils/starknetUtils'; | ||
import { getNetworkFromChainId, getSignTxnTxt } from './utils/snapUtils'; | ||
import { DialogType } from '@metamask/rpc-methods'; | ||
import { heading, panel } from '@metamask/snaps-ui'; | ||
import { logger } from './utils/logger'; | ||
|
||
export async function signDeclareTransaction(params: ApiParams): Promise<Signature | boolean> { | ||
try { | ||
const { state, keyDeriver, requestParams, wallet } = params; | ||
const requestParamsObj = requestParams as SignDeclareTransactionRequestParams; | ||
const signerAddress = requestParamsObj.signerAddress; | ||
const network = getNetworkFromChainId(state, requestParamsObj.chainId); | ||
const { privateKey } = await getKeysFromAddress(keyDeriver, network, state, signerAddress); | ||
|
||
logger.log(`signDeclareTransaction params: ${toJson(requestParamsObj.transaction, 2)}}`); | ||
|
||
const snapComponents = getSignTxnTxt(signerAddress, network, requestParamsObj.transaction); | ||
|
||
if (requestParamsObj.enableAutherize === true) { | ||
const response = await wallet.request({ | ||
method: 'snap_dialog', | ||
params: { | ||
type: DialogType.Confirmation, | ||
content: panel([heading('Do you want to sign this transaction?'), ...snapComponents]), | ||
}, | ||
}); | ||
|
||
if (!response) return false; | ||
} | ||
|
||
return await signDeclareTransactionUtil(privateKey, requestParamsObj.transaction); | ||
} catch (error) { | ||
logger.error(`Problem found: ${error}`); | ||
throw error; | ||
} | ||
} |
Oops, something went wrong.