diff --git a/wrapper/go-wrapper/core/coin.go b/wrapper/go-wrapper/core/coin.go index 56a05364e63..4cb9b46f90b 100644 --- a/wrapper/go-wrapper/core/coin.go +++ b/wrapper/go-wrapper/core/coin.go @@ -21,6 +21,8 @@ const ( CoinTypeCosmos CoinType = C.TWCoinTypeCosmos CoinTypeAptos CoinType = C.TWCoinTypeAptos CoinTypeNEAR CoinType = C.TWCoinTypeNEAR + CoinTypeICP CoinType = C.TWCoinTypeInternetComputer + CoinTypeStellar CoinType = C.TWCoinTypeStellar ) func (c CoinType) GetName() string { diff --git a/wrapper/go-wrapper/core/stellar.go b/wrapper/go-wrapper/core/stellar.go new file mode 100644 index 00000000000..61f430fcf27 --- /dev/null +++ b/wrapper/go-wrapper/core/stellar.go @@ -0,0 +1,4 @@ +package core + +const StellarPassphrase_Stellar string = "Public Global Stellar Network ; September 2015" +const StellarPassphrase_Kin string = "Kin Mainnet ; December 2018" diff --git a/wrapper/go-wrapper/core/utils.go b/wrapper/go-wrapper/core/utils.go new file mode 100644 index 00000000000..4fd332538e5 --- /dev/null +++ b/wrapper/go-wrapper/core/utils.go @@ -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) +} diff --git a/wrapper/go-wrapper/main.go b/wrapper/go-wrapper/main.go index e579181b542..55948ab8a10 100644 --- a/wrapper/go-wrapper/main.go +++ b/wrapper/go-wrapper/main.go @@ -55,6 +55,8 @@ func main() { } printWallet(tw) sample.TestAptos() + sample.TestICP() + sample.TestStellar() } func createEthTransaction(ew *core.Wallet) string { diff --git a/wrapper/go-wrapper/sample/icp.go b/wrapper/go-wrapper/sample/icp.go new file mode 100644 index 00000000000..d43829fbe4f --- /dev/null +++ b/wrapper/go-wrapper/sample/icp.go @@ -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) + + fmt.Println("preSigningOutput:", &preSigningOutput) + + fmt.Println("sigHash:", hex.EncodeToString(preSigningOutput.DataHash)) +} diff --git a/wrapper/go-wrapper/sample/near.go b/wrapper/go-wrapper/sample/near.go new file mode 100644 index 00000000000..89fa49767d6 --- /dev/null +++ b/wrapper/go-wrapper/sample/near.go @@ -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())) +} diff --git a/wrapper/go-wrapper/sample/stellar.go b/wrapper/go-wrapper/sample/stellar.go new file mode 100644 index 00000000000..3241e7477c7 --- /dev/null +++ b/wrapper/go-wrapper/sample/stellar.go @@ -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) +}