-
Notifications
You must be signed in to change notification settings - Fork 0
go-wrapper for Stellar #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package core | ||
|
||
const StellarPassphrase_Stellar string = "Public Global Stellar Network ; September 2015" | ||
const StellarPassphrase_Kin string = "Kin Mainnet ; December 2018" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package core | ||
|
||
import "fmt" | ||
|
||
func WalletInfo(w *Wallet) { | ||
fmt.Printf("%s wallet: \n", w.CoinType.GetName()) | ||
fmt.Printf("\t address: %s \n", w.Address) | ||
fmt.Printf("\t pri key: %s \n", w.PriKey) | ||
fmt.Printf("\t pub key: %s \n", w.PubKey) | ||
} | ||
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,50 @@ | ||||||||||||||||||||||||||||||||||||||||||
package sample | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
import ( | ||||||||||||||||||||||||||||||||||||||||||
"encoding/hex" | ||||||||||||||||||||||||||||||||||||||||||
"fmt" | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
"github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/core" | ||||||||||||||||||||||||||||||||||||||||||
"github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/internetcomputer" | ||||||||||||||||||||||||||||||||||||||||||
"github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/transactioncompiler" | ||||||||||||||||||||||||||||||||||||||||||
"google.golang.org/protobuf/proto" | ||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
func TestICP() { | ||||||||||||||||||||||||||||||||||||||||||
mn := "confirm bleak useless tail chalk destroy horn step bulb genuine attract split" | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
fmt.Println("==> mnemonic is valid: ", core.IsMnemonicValid(mn)) | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
// bitcoin wallet | ||||||||||||||||||||||||||||||||||||||||||
bw, err := core.CreateWalletWithMnemonic(mn, core.CoinTypeICP) | ||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||
panic(err) | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
core.WalletInfo(bw) | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
input := &internetcomputer.SigningInput{ | ||||||||||||||||||||||||||||||||||||||||||
Transaction: &internetcomputer.Transaction{ | ||||||||||||||||||||||||||||||||||||||||||
TransactionOneof: &internetcomputer.Transaction_Transfer_{ | ||||||||||||||||||||||||||||||||||||||||||
Transfer: &internetcomputer.Transaction_Transfer{ | ||||||||||||||||||||||||||||||||||||||||||
ToAccountIdentifier: "943d12e762f43806782f524b8f90297298a6d79e4749b41b585ec427409c826a", | ||||||||||||||||||||||||||||||||||||||||||
Amount: 100000000, | ||||||||||||||||||||||||||||||||||||||||||
Memo: 0, | ||||||||||||||||||||||||||||||||||||||||||
CurrentTimestampNanos: 1691709940000000000, | ||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
fmt.Println("input:", input) | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
txInputData, _ := proto.Marshal(input) | ||||||||||||||||||||||||||||||||||||||||||
msgForSign := core.PreImageHashes(core.CoinTypeICP, txInputData) | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
fmt.Println("msgForSign:", msgForSign) | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
var preSigningOutput transactioncompiler.PreSigningOutput | ||||||||||||||||||||||||||||||||||||||||||
proto.Unmarshal(msgForSign, &preSigningOutput) | ||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+39
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add error handling for protobuf operations. The - txInputData, _ := proto.Marshal(input)
+ txInputData, err := proto.Marshal(input)
+ if err != nil {
+ panic(err)
+ }
msgForSign := core.PreImageHashes(core.CoinTypeICP, txInputData)
fmt.Println("msgForSign:", msgForSign)
var preSigningOutput transactioncompiler.PreSigningOutput
- proto.Unmarshal(msgForSign, &preSigningOutput)
+ err = proto.Unmarshal(msgForSign, &preSigningOutput)
+ if err != nil {
+ panic(err)
+ } 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
fmt.Println("preSigningOutput:", &preSigningOutput) | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
fmt.Println("sigHash:", hex.EncodeToString(preSigningOutput.DataHash)) | ||||||||||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package sample | ||
|
||
import ( | ||
"encoding/hex" | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/core" | ||
"github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/near" | ||
"github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/transactioncompiler" | ||
"google.golang.org/protobuf/proto" | ||
) | ||
|
||
func TestNEAR() { | ||
|
||
signatureBytes, _ := hex.DecodeString("969a83332186ee9755e4839325525806e189a3d2d2bb4b4760e94443e97e1c4f22deeef0059a8e9713100eda6e19144da7e8a0ef7e539b20708ba1d8d021bd01") | ||
blockHashBytes, _ := hex.DecodeString("0fa473fd26901df296be6adc4cc4df34d040efa2435224b6986910e630c2fef6") | ||
pubKeyBytes, _ := hex.DecodeString("917b3d268d4b58f7fec1b150bd68d69be3ee5d4cc39855e341538465bb77860d") | ||
var transferAmount [16]byte | ||
transferAmount[0] = 1 | ||
|
||
fmt.Println("hex amount:", hex.EncodeToString(transferAmount[:])) | ||
|
||
input := near.SigningInput{ | ||
SignerId: "test.near", | ||
ReceiverId: "whatever.near", | ||
BlockHash: blockHashBytes, | ||
Nonce: 1, | ||
PublicKey: pubKeyBytes, | ||
Actions: []*near.Action{ | ||
&near.Action{ | ||
Payload: &near.Action_Transfer{ | ||
Transfer: &near.Transfer{ | ||
Deposit: transferAmount[:], | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
txInputData, _ := proto.Marshal(&input) | ||
msgForSign := core.PreImageHashes(core.CoinTypeNEAR, txInputData) | ||
|
||
var preSigningOutput transactioncompiler.PreSigningOutput | ||
proto.Unmarshal(msgForSign, &preSigningOutput) | ||
|
||
fmt.Println("sigHash:", hex.EncodeToString(preSigningOutput.DataHash)) | ||
|
||
valid := core.PublicKeyVerify(pubKeyBytes, core.PublicKeyTypeED25519, signatureBytes, preSigningOutput.DataHash) | ||
if !valid { | ||
panic(errors.New("verification failed")) | ||
} | ||
fmt.Println("Signature verification successfully") | ||
|
||
txOutput := core.CompileWithSignatures(core.CoinTypeNEAR, txInputData, [][]byte{signatureBytes}, [][]byte{pubKeyBytes}) | ||
|
||
var output near.SigningOutput | ||
err := proto.Unmarshal(txOutput, &output) | ||
if err != nil { | ||
panic(errors.New("unmarshal output failed")) | ||
} | ||
fmt.Println("Message for broadcast:", hex.EncodeToString(output.SignedTransaction)) | ||
fmt.Println("Transaction hash:", hex.EncodeToString(output.GetHash())) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package sample | ||
|
||
import ( | ||
"encoding/hex" | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/core" | ||
"github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/stellar" | ||
"github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/transactioncompiler" | ||
"google.golang.org/protobuf/proto" | ||
) | ||
|
||
func TestStellar() { | ||
input := &stellar.SigningInput{ | ||
Passphrase: core.StellarPassphrase_Stellar, | ||
Account: "GAE2SZV4VLGBAPRYRFV2VY7YYLYGYIP5I7OU7BSP6DJT7GAZ35OKFDYI", | ||
Fee: 1000, | ||
Sequence: 2, | ||
OperationOneof: &stellar.SigningInput_OpPayment{ | ||
OpPayment: &stellar.OperationPayment{ | ||
Destination: "GDCYBNRRPIHLHG7X7TKPUPAZ7WVUXCN3VO7WCCK64RIFV5XM5V5K4A52", | ||
Amount: 10000000, | ||
}, | ||
}, | ||
MemoTypeOneof: &stellar.SigningInput_MemoText{ | ||
MemoText: &stellar.MemoText{ | ||
Text: "Hello, world!", | ||
}, | ||
}, | ||
} | ||
|
||
txInputData, _ := proto.Marshal(input) | ||
preimage := core.PreImageHashes(core.CoinTypeStellar, txInputData) | ||
|
||
var preSigningOutput transactioncompiler.PreSigningOutput | ||
proto.Unmarshal(preimage, &preSigningOutput) | ||
fmt.Println("[SigHash]:", hex.EncodeToString(preSigningOutput.DataHash)) | ||
|
||
signature, _ := hex.DecodeString("5042574491827aaccbce1e2964c05098caba06194beb35e595aabfec9f788516a833f755f18144f4a2eedb3123d180f44e7c16037d00857c5c5b7033ebac2c01") | ||
pubkey, _ := hex.DecodeString("09a966bcaacc103e38896baae3f8c2f06c21fd47dd4f864ff0d33f9819df5ca2") | ||
|
||
valid := core.PublicKeyVerify(pubkey, core.PublicKeyTypeED25519, signature, preSigningOutput.DataHash) | ||
if !valid { | ||
panic(errors.New("verification failed")) | ||
} | ||
fmt.Println("Valid Signature") | ||
|
||
txOutput := core.CompileWithSignatures(core.CoinTypeStellar, txInputData, [][]byte{signature}, [][]byte{pubkey}) | ||
|
||
var output stellar.SigningOutput | ||
err := proto.Unmarshal(txOutput, &output) | ||
if err != nil { | ||
panic(errors.New("unmarshal output failed")) | ||
} | ||
fmt.Println("Message for broadcast:", &output) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix compilation error: undefined Wallet type.
The
Wallet
type is not defined or imported in this package, causing a compilation error as indicated by the static analysis tool.The
Wallet
type needs to be imported or this function should be moved to a package whereWallet
is defined. Looking at the codebase,Wallet
appears to be defined in the samecore
package, so you may need to check if there's a missing file or if theWallet
struct definition needs to be added.Additionally, this function duplicates the
printWallet
function frommain.go
. Consider consolidating this functionality.+// Add the Wallet struct definition or import it from the appropriate location func WalletInfo(w *Wallet) { fmt.Printf("%s wallet: \n", w.CoinType.GetName()) fmt.Printf("\t address: %s \n", w.Address) fmt.Printf("\t pri key: %s \n", w.PriKey) fmt.Printf("\t pub key: %s \n", w.PubKey) }
🤖 Prompt for AI Agents