Skip to content

Commit

Permalink
Merge pull-request #39
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewkmin committed Feb 20, 2024
2 parents f49bf8f + 6eddf85 commit 9b2eb8e
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package main demonstrates an API client which returns the UserID of its API key.
// Package main demonstrates an API client which signs a raw payload with a private key ID or wallet account.
package main

import (
Expand Down Expand Up @@ -33,7 +33,7 @@ func main() {
Type: models.TransactionTypeEthereum.Pointer(),
UnsignedTransaction: &unsignedTransaction,
},
Type: (*string)(models.ActivityTypeSignTransaction.Pointer()),
Type: (*string)(models.ActivityTypeSignTransactionV2.Pointer()),
})

signResp, err := client.V0().Signing.SignTransaction(pkParams, client.Authenticator)
Expand Down
45 changes: 45 additions & 0 deletions examples/signing/sign_transaction/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Package main demonstrates an API client which signs a transaction with a private key ID or wallet account.
package main

import (
"fmt"
"log"
"strconv"
"time"

"github.com/tkhq/go-sdk"
"github.com/tkhq/go-sdk/pkg/api/client/signing"
"github.com/tkhq/go-sdk/pkg/api/models"
)

func main() {
// NB: make sure to create and register an API key, first.
client, err := sdk.New("default")
if err != nil {
log.Fatal("failed to create new SDK client:", err)
}

timestamp := time.Now().UnixMilli()
timestampString := strconv.FormatInt(timestamp, 10)

var sighWith string // can be either a private key ID or a wallet account address
var unsignedTransaction string // no 0x prefix necessary

pkParams := signing.NewSignTransactionParams().WithBody(&models.SignTransactionRequest{
OrganizationID: client.DefaultOrganization(),
TimestampMs: &timestampString,
Parameters: &models.SignTransactionIntentV2{
SignWith: &sighWith,
Type: models.TransactionTypeEthereum.Pointer(),
UnsignedTransaction: &unsignedTransaction,
},
Type: (*string)(models.ActivityTypeSignTransactionV2.Pointer()),
})

signResp, err := client.V0().Signing.SignTransaction(pkParams, client.Authenticator)
if err != nil {
log.Fatal("failed to make SignTransaction request:", err)
}

fmt.Printf("Signed tx: %v\n", *signResp.Payload.Activity.Result.SignTransactionResult.SignedTransaction)
}
51 changes: 51 additions & 0 deletions examples/wallets/create_wallet/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Package main demonstrates an API client which creates a new wallet with a wallet account.
package main

import (
"fmt"
"log"
"strconv"
"time"

"github.com/tkhq/go-sdk"
"github.com/tkhq/go-sdk/pkg/api/client/wallets"
"github.com/tkhq/go-sdk/pkg/api/models"
)

func main() {
// NB: make sure to create and register an API key, first.
client, err := sdk.New("default")
if err != nil {
log.Fatal("failed to create new SDK client:", err)
}

walletName := "New Wallet"
path := "m/44'/60'/0'/0/0"

timestamp := time.Now().UnixMilli()
timestampString := strconv.FormatInt(timestamp, 10)

params := wallets.NewCreateWalletParams().WithBody(&models.CreateWalletRequest{
OrganizationID: client.DefaultOrganization(),
Parameters: &models.CreateWalletIntent{
WalletName: &walletName,
Accounts: []*models.WalletAccountParams{
{
AddressFormat: models.AddressFormatEthereum.Pointer(),
Curve: models.CurveSecp256k1.Pointer(),
Path: &path,
PathFormat: models.PathFormatBip32.Pointer(),
},
},
},
TimestampMs: &timestampString,
Type: (*string)(models.ActivityTypeCreateWallet.Pointer()),
})

resp, err := client.V0().Wallets.CreateWallet(params, client.Authenticator)
if err != nil {
log.Fatal("failed to make Wallets CreateWallet request:", err)
}

fmt.Printf("New wallet: %v\n", resp.Payload.Activity.Result.CreateWalletResult.WalletID)
}
49 changes: 49 additions & 0 deletions examples/wallets/create_wallet_accounts/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Package main demonstrates an API client which creates new wallet accounts.
package main

import (
"fmt"
"log"
"strconv"
"time"

"github.com/tkhq/go-sdk"
"github.com/tkhq/go-sdk/pkg/api/client/wallets"
"github.com/tkhq/go-sdk/pkg/api/models"
)

func main() {
// NB: make sure to create and register an API key, first.
client, err := sdk.New("default")
if err != nil {
log.Fatal("failed to create new SDK client:", err)
}

path := "m/44'/60'/0'/0/0"

timestamp := time.Now().UnixMilli()
timestampString := strconv.FormatInt(timestamp, 10)

params := wallets.NewCreateWalletAccountsParams().WithBody(&models.CreateWalletAccountsRequest{
OrganizationID: client.DefaultOrganization(),
Parameters: &models.CreateWalletAccountsIntent{
Accounts: []*models.WalletAccountParams{
{
AddressFormat: models.AddressFormatEthereum.Pointer(),
Curve: models.CurveSecp256k1.Pointer(),
Path: &path,
PathFormat: models.PathFormatBip32.Pointer(),
},
},
},
TimestampMs: &timestampString,
Type: (*string)(models.ActivityTypeCreateWalletAccounts.Pointer()),
})

resp, err := client.V0().Wallets.CreateWalletAccounts(params, client.Authenticator)
if err != nil {
log.Fatal("failed to make Wallets CreateWalletAccounts request:", err)
}

fmt.Printf("New wallet account: %v\n", resp.Payload.Activity.Result.CreateWalletAccountsResult.Addresses[0])
}

0 comments on commit 9b2eb8e

Please sign in to comment.