-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commit 9cb940b Author: Thiago Ribeiro <[email protected]> Date: Thu Dec 19 23:10:28 2024 -0300 Thiagodeev/rpcv08 final changes (#644) * Adjusts TransactionStatus * Adjusts EstimateFee * Fixes blockTest error * Adds GetStorageProof method (#635) * implement rpcv8 GetStorageProof method * Adds GetMessagesStatus method (#634) * Added GetMessagesStatus method * PR comment fixes * Fix MerkleNode type * Updates PendingBlockReader type * Updates ExecutionResources and remove ComputationResources * Fixes failing tests and improves Error() resp * Adds TODO comments and set a pointer to Marshal method * Thiagodeev/rpcv08 write methods, blockHeader and error 53 (#626) Update write methods, error 53 and block header for rpc08 * Adjusts EstimateFee commit 4ca79eb Merge: 9007483 8ecf779 Author: Thiago Ribeiro <[email protected]> Date: Wed Dec 18 00:35:32 2024 -0300 Merge branch 'main' into v0.8.0 commit 8ecf779 Author: Thiago Ribeiro <[email protected]> Date: Fri Dec 13 10:30:35 2024 -0300 Implements SNIP-12 (#637) * General semantic updates and EncodeType adjustment * Improvements and bug fixes * Implements typedData unmarshal * Adds Message support on Unmarshal typedData * Rename files and create types file * Creates TestGeneral_CreateMessageWithTypes * Clears some curve methods and adds Poseidon method * Adds revision.go file, new Revision field of TypedData * Basic implementation working with a rev 0 typedData * Rename files * Some code adjustments * Adds new examples from starknet.js and implements new mock logic * init function on revision package * Adds first version of Validate feature * Adds revision 1 support to encodeType * Adds 'selector' support in encodeData * restructs encodeData * adds handleStandardTypes and handleArrays functions * support to arrays, new types and new Domain unmarshal * fixed support to bool, new example being tested * fixes errors in encodeType, 'example_presetTypes' supported * implements merkletree encode * adds support to 'mail_StructArray' json example * Fixes error inStringToByteArrFelt func, 'v1Nested' example passing * Started to refactor 'encodeType' func * Fixes bug with merkletree * Creates the verifyType func * implements enum encoding * Removes the validation method, it will be added later * creates big example for testing purpose * removes the types file * adds code comments and descriptions * rename folder and file names * creates typedData example and change READMEs * Update utils/Felt.go Co-authored-by: Rian Hughes <[email protected]> * Update utils/keccak.go Co-authored-by: Rian Hughes <[email protected]> * addresses Rian's comment about GetMessageHash * Revert enum wrong encode as it was fixed by starknet.js * Creates ValidationSignature helper * Removes the StrToFelt utility * Improves 'chainId' validation * Changes private fields of TypedData to public --------- Co-authored-by: Rian Hughes <[email protected]> commit 1c399f4 Author: Thiago Ribeiro <[email protected]> Date: Wed Dec 11 12:13:13 2024 -0300 Merge PR #592 to main (#647) * fix::> introduced comman AddTransaction function in account package * fix::> replace all the instances of Add<Type>Transaction in example/test with AddTransaction * fix::> func name and doc changes made * fix::> account_test.go changed * fix::> examples error solved * fix::> Removed type assertions, created generic TransactionResponse struct, and transaction type converter * fix::> removed unnecessary lines * fix:> made required changes * fix::> removed unnecessary comments * fix::> renamed test function --------- Co-authored-by: Abhinav Prakash <[email protected]> Co-authored-by: Rian Hughes <[email protected]> commit 9007483 Author: Thiago Ribeiro <[email protected]> Date: Wed Nov 6 11:26:01 2024 -0300 starknet_getCompiledCasm (#642) * implement starknet_getCompiledCasm for RPCv8 commit 98d2b5c Author: Thiago Ribeiro <[email protected]> Date: Mon Oct 28 11:24:53 2024 -0300 Adds GetMessagesStatus method (#634) * Added GetMessagesStatus method * PR comment fixes commit ae6e233 Author: Thiago Ribeiro <[email protected]> Date: Mon Oct 28 07:20:01 2024 -0300 Adds GetStorageProof method (#635) * implement rpcv8 GetStorageProof method commit 75425d3 Author: thiagodeev <[email protected]> Date: Mon Sep 30 10:08:19 2024 -0300 Fixes blockTest error commit de722c1 Author: thiagodeev <[email protected]> Date: Mon Sep 30 10:07:56 2024 -0300 Adjusts EstimateFee commit b97a149 Author: thiagodeev <[email protected]> Date: Mon Sep 30 09:31:31 2024 -0300 Adjusts TransactionStatus
- Loading branch information
1 parent
28a28aa
commit 59ff5c7
Showing
37 changed files
with
2,300 additions
and
582 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,6 @@ rpc*/.env.testnet | |
|
||
tmp/ | ||
|
||
examples/**/*.json | ||
examples/**/*.sum | ||
|
||
*/**/*abi.json | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
This example shows how to sign and verify a typed data. | ||
|
||
Steps: | ||
1. Rename the ".env.template" file located at the root of the "examples" folder to ".env" | ||
1. Uncomment, and assign your Sepolia testnet endpoint to the `RPC_PROVIDER_URL` variable in the ".env" file | ||
1. Uncomment, and assign your account address to the `ACCOUNT_ADDRESS` variable in the ".env" file (make sure to have a few ETH in it) | ||
1. Uncomment, and assign your starknet public key to the `PUBLIC_KEY` variable in the ".env" file | ||
1. Uncomment, and assign your private key to the `PRIVATE_KEY` variable in the ".env" file | ||
1. Make sure you are in the "typedData" directory | ||
1. Execute `go run main.go` | ||
|
||
The message hash, signature and the verification result will be printed at the end of the execution. |
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,35 @@ | ||
{ | ||
"types": { | ||
"StarkNetDomain": [ | ||
{ "name": "name", "type": "felt" }, | ||
{ "name": "version", "type": "felt" }, | ||
{ "name": "chainId", "type": "felt" } | ||
], | ||
"Person": [ | ||
{ "name": "name", "type": "felt" }, | ||
{ "name": "wallet", "type": "felt" } | ||
], | ||
"Mail": [ | ||
{ "name": "from", "type": "Person" }, | ||
{ "name": "to", "type": "Person" }, | ||
{ "name": "contents", "type": "felt" } | ||
] | ||
}, | ||
"primaryType": "Mail", | ||
"domain": { | ||
"name": "StarkNet Mail", | ||
"version": "1", | ||
"chainId": 1 | ||
}, | ||
"message": { | ||
"from": { | ||
"name": "Cow", | ||
"wallet": "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826" | ||
}, | ||
"to": { | ||
"name": "Bob", | ||
"wallet": "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB" | ||
}, | ||
"contents": "Hello, Bob!" | ||
} | ||
} |
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,91 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"math/big" | ||
"os" | ||
|
||
"github.com/NethermindEth/starknet.go/account" | ||
"github.com/NethermindEth/starknet.go/curve" | ||
"github.com/NethermindEth/starknet.go/rpc" | ||
"github.com/NethermindEth/starknet.go/typedData" | ||
"github.com/NethermindEth/starknet.go/utils" | ||
|
||
setup "github.com/NethermindEth/starknet.go/examples/internal" | ||
) | ||
|
||
// NOTE : Please add in your keys only for testing purposes, in case of a leak you would potentially lose your funds. | ||
|
||
func main() { | ||
// Setup the account | ||
accnt := localSetup() | ||
fmt.Println("Account address:", accnt.AccountAddress) | ||
|
||
// This is how you can initialize a typed data from a JSON file | ||
var ttd typedData.TypedData | ||
content, err := os.ReadFile("./baseExample.json") | ||
if err != nil { | ||
panic(fmt.Errorf("fail to read file: %w", err)) | ||
} | ||
err = json.Unmarshal(content, &ttd) | ||
if err != nil { | ||
panic(fmt.Errorf("fail to unmarshal TypedData: %w", err)) | ||
} | ||
|
||
// This is how you can get the message hash linked to your account address | ||
messageHash, err := ttd.GetMessageHash(accnt.AccountAddress.String()) | ||
if err != nil { | ||
panic(fmt.Errorf("fail to get message hash: %w", err)) | ||
} | ||
fmt.Println("Message hash:", messageHash) | ||
|
||
// This is how you can sign the message hash | ||
signature, err := accnt.Sign(context.Background(), messageHash) | ||
if err != nil { | ||
panic(fmt.Errorf("fail to sign message: %w", err)) | ||
} | ||
fmt.Println("Signature:", signature) | ||
|
||
// This is how you can verify the signature | ||
isValid := curve.VerifySignature(messageHash.String(), signature[0].String(), signature[1].String(), setup.GetPublicKey()) | ||
fmt.Println("Verification result:", isValid) | ||
} | ||
|
||
func localSetup() *account.Account { | ||
// Load variables from '.env' file | ||
rpcProviderUrl := setup.GetRpcProviderUrl() | ||
accountAddress := setup.GetAccountAddress() | ||
accountCairoVersion := setup.GetAccountCairoVersion() | ||
privateKey := setup.GetPrivateKey() | ||
publicKey := setup.GetPublicKey() | ||
|
||
// Initialize connection to RPC provider | ||
client, err := rpc.NewProvider(rpcProviderUrl) | ||
if err != nil { | ||
panic(fmt.Sprintf("Error dialing the RPC provider: %s", err)) | ||
} | ||
|
||
// Initialize the account memkeyStore (set public and private keys) | ||
ks := account.NewMemKeystore() | ||
privKeyBI, ok := new(big.Int).SetString(privateKey, 0) | ||
if !ok { | ||
panic("Fail to convert privKey to bitInt") | ||
} | ||
ks.Put(publicKey, privKeyBI) | ||
|
||
// Here we are converting the account address to felt | ||
accountAddressInFelt, err := utils.HexToFelt(accountAddress) | ||
if err != nil { | ||
fmt.Println("Failed to transform the account address, did you give the hex address?") | ||
panic(err) | ||
} | ||
// Initialize the account | ||
accnt, err := account.NewAccount(client, accountAddressInFelt, publicKey, ks, accountCairoVersion) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return accnt | ||
} |
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
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.