Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
module github.com/Cramiumlabs/wallet-core

go 1.22.5
go 1.23.0

require google.golang.org/protobuf v1.36.6
toolchain go1.23.10

require (
golang.org/x/crypto v0.39.0
google.golang.org/protobuf v1.36.6
)

require golang.org/x/sys v0.33.0 // indirect
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
golang.org/x/crypto v0.39.0 h1:SHs+kF4LP+f+p14esP5jAoDpHU8Gu/v9lFRK6IT5imM=
golang.org/x/crypto v0.39.0/go.mod h1:L+Xg3Wf6HoL4Bn4238Z6ft6KfEpN0tJGo53AAPC632U=
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
Expand Down
2 changes: 2 additions & 0 deletions wrapper/go-wrapper/core/coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const (
CoinTypeLitecoin CoinType = C.TWCoinTypeLitecoin
CoinTypeDogecoin CoinType = C.TWCoinTypeDogecoin
CoinTypeCosmos CoinType = C.TWCoinTypeCosmos
CoinTypeAptos CoinType = C.TWCoinTypeAptos
CoinTypeNEAR CoinType = C.TWCoinTypeNEAR
)

func (c CoinType) GetName() string {
Expand Down
15 changes: 8 additions & 7 deletions wrapper/go-wrapper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ func main() {
}
printWallet(ew)

// tron wallet
tw, err := core.CreateWalletWithMnemonic(mn, core.CoinTypeTron)
if err != nil {
panic(err)
}
printWallet(tw)

// Ethereum transaction
ethTxn := createEthTransaction(ew)
fmt.Println("Ethereum signed tx:")
Expand All @@ -54,6 +47,14 @@ func main() {
sample.ExternalSigningDemo()
sample.TestCardano()
sample.TestCosmos()

// Aptos wallet
tw, err := core.CreateWalletWithMnemonic(mn, core.CoinTypeAptos)
if err != nil {
panic(err)
}
printWallet(tw)
sample.TestAptos()
}

func createEthTransaction(ew *core.Wallet) string {
Expand Down
76 changes: 76 additions & 0 deletions wrapper/go-wrapper/sample/aptos.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package sample

import (
"encoding/hex"
"errors"
"fmt"

"golang.org/x/crypto/sha3"

"github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/core"
"github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/aptos"
"github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/protos/transactioncompiler"
"google.golang.org/protobuf/proto"
)

func TestAptos() {
// Successfully broadcasted https://explorer.aptoslabs.com/txn/0xb4d62afd3862116e060dd6ad9848ccb50c2bc177799819f1d29c059ae2042467?network=devnet
expectedTxID := "0xb4d62afd3862116e060dd6ad9848ccb50c2bc177799819f1d29c059ae2042467"
signingInput := &aptos.SigningInput{
ChainId: 33,
Sender: "0x07968dab936c1bad187c60ce4082f307d030d780e91e694ae03aef16aba73f30",
SequenceNumber: 99,
TransactionPayload: &aptos.SigningInput_Transfer{
Transfer: &aptos.TransferMessage{
To: "0x07968dab936c1bad187c60ce4082f307d030d780e91e694ae03aef16aba73f30",
Amount: 1000,
},
},
MaxGasAmount: 3296766,
GasUnitPrice: 100,
ExpirationTimestampSecs: 3664390082,
}
fmt.Println("signingInput:", signingInput)

txInputData, _ := proto.Marshal(signingInput)
preimage := core.PreImageHashes(core.CoinTypeAptos, txInputData)

var preSigningOutput transactioncompiler.PreSigningOutput
proto.Unmarshal(preimage, &preSigningOutput)
fmt.Println("[SigHash]:", preSigningOutput.Data)

publicKey, _ := hex.DecodeString("ea526ba1710343d953461ff68641f1b7df5f23b9042ffa2d2a798d3adb3f3d6c")
signature, _ := hex.DecodeString("5707246db31e2335edc4316a7a656a11691d1d1647f6e864d1ab12f43428aaaf806cf02120d0b608cdd89c5c904af7b137432aacdd60cc53f9fad7bd33578e01")

valid := core.PublicKeyVerify(publicKey, core.PublicKeyTypeED25519, signature, preSigningOutput.Data)
if !valid {
panic(errors.New("verification failed"))
}
fmt.Println("Signature verification successfully")

txOutput := core.CompileWithSignatures(core.CoinTypeAptos, txInputData, [][]byte{signature}, [][]byte{publicKey})

var output aptos.SigningOutput
err := proto.Unmarshal(txOutput, &output)
if err != nil {
panic(errors.New("unmarshal output failed"))
}
fmt.Println("Message for broadcast:", output.GetJson())

txID := AptosTxID(output.Encoded)
if expectedTxID != txID {
panic(errors.New("the transaction id mismatched"))
}
fmt.Println("Correct transaction ID. Simulation process is done!")
}

func AptosTxID(encodedSignedTx []byte) string {
prefix := sha3.Sum256([]byte("APTOS::Transaction"))
h := sha3.New256()
h.Write(prefix[:])
h.Write([]byte{0x00})
h.Write(encodedSignedTx)
var out [32]byte
h.Sum(out[:0])
return "0x" + hex.EncodeToString(out[:])
}
Loading