Skip to content

Commit

Permalink
WIP signature
Browse files Browse the repository at this point in the history
  • Loading branch information
rianhughes committed Jul 31, 2023
1 parent 8d452fd commit 74cb806
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
51 changes: 51 additions & 0 deletions examples/deployAccount/helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package main

import (
"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/starknet.go/rpcv02"
)

func signDeployAccountTransaction(tx rpcv02.BroadcastedDeployAccountTransaction, contractAddress *felt.Felt, chainID rpcv02.chainID) {
msgHash := calculateDeployAccountTransactionHash(tx, contractAddress, chainId)
return starkCurve.sign(msgHash, this.pk)
}

func calculateDeployAccountTransactionHash(tx rpcv02.BroadcastedDeployAccountTransaction, contractAddress *felt.Felt) *felt.Felt {
calldata := []*felt.Felt{tx.ClassHash, tx.ContractAddressSalt}
calldata = append(calldata, tx.ConstructorCalldata...)

return calculateTransactionHashCommon(
rpcv02.TransactionHashPrefix.DEPLOY_ACCOUNT,
tx.Version,
contractAddress,
0,
tx.ConstructorCalldata,
tx.MaxFee,
chainID,
[]*felt.Felt{tx.Nonce},
)
}

func calculateTransactionHashCommon(
txHashPrefix *felt.Felt,
version rpcv02.TransactionVersion,
contractAddress *felt.Felt,
entryPointSelector *felt.Felt,
calldata *felt.Felt,
maxFee *felt.Felt,
chainId rpcv02.chainID,
additionalData []*felt.Felt) *felt.Felt {
calldataHash := computeHashOnElements(calldata)
dataToHash := []*felt.Felt{
txHashPrefix,
version,
contractAddress,
entryPointSelector,
calldataHash,
maxFee,
chainId,
}
dataToHash = append(dataToHash, additionalData...)

return computeHashOnElements(dataToHash)
}
1 change: 1 addition & 0 deletions examples/deployAccount/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ func main() {
// NEXT: construct tx correctly
// To Sign
// ref : https://github.com/0xs34n/starknet.js/blob/develop/src/signer/default.ts#L63C1-L63C46
// signDeployAccountTransaction -> calculateDeployAccountTransactionHash -> calculateTransactionHashCommon -> computeHashOnElements

tx := rpcv02.BroadcastedDeployAccountTransaction{
BroadcastedTxnCommonProperties: rpcv02.BroadcastedTxnCommonProperties{
Expand Down

0 comments on commit 74cb806

Please sign in to comment.