From db6654aa30ad15d92754475ef8461beb53ecc797 Mon Sep 17 00:00:00 2001 From: Greg Nazario Date: Tue, 19 Nov 2024 15:14:20 -0500 Subject: [PATCH 1/2] [view] Allow querying APT balance and FA properties by version --- CHANGELOG.md | 2 ++ client.go | 6 ++--- fungible_asset_client.go | 56 ++++++++++++++++++++-------------------- nodeClient.go | 4 +-- 4 files changed, 35 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c95a9f2..6f7fe7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ adheres to the format set out by [Keep a Changelog](https://keepachangelog.com/e # Unreleased +- Add support for optional ledger version in FA functions and APT balance + # v1.2.0 (11/15/2024) - [`Fix`][`Breaking`] Fix MultiKey implementation to be more consistent with the rest of the SDKs diff --git a/client.go b/client.go index 2e27152..b2b7612 100644 --- a/client.go +++ b/client.go @@ -370,7 +370,7 @@ type AptosRpcClient interface { EstimateGasPrice() (info EstimateGasInfo, err error) // AccountAPTBalance retrieves the APT balance in the account - AccountAPTBalance(address AccountAddress) (uint64, error) + AccountAPTBalance(address AccountAddress, ledgerVersion ...uint64) (uint64, error) // NodeAPIHealthCheck checks if the node is within durationSecs of the current time, if not provided the node default is used NodeAPIHealthCheck(durationSecs ...uint64) (api.HealthCheckResponse, error) @@ -825,8 +825,8 @@ func (client *Client) EstimateGasPrice() (info EstimateGasInfo, err error) { } // AccountAPTBalance retrieves the APT balance in the account -func (client *Client) AccountAPTBalance(address AccountAddress) (uint64, error) { - return client.nodeClient.AccountAPTBalance(address) +func (client *Client) AccountAPTBalance(address AccountAddress, ledgerVersion ...uint64) (uint64, error) { + return client.nodeClient.AccountAPTBalance(address, ledgerVersion...) } // QueryIndexer queries the indexer using GraphQL to fill the `query` struct with data. See examples in the indexer client on how to make queries diff --git a/fungible_asset_client.go b/fungible_asset_client.go index f52de3d..6216548 100644 --- a/fungible_asset_client.go +++ b/fungible_asset_client.go @@ -90,8 +90,8 @@ func (client *FungibleAssetClient) PrimaryStoreExists(owner *AccountAddress) (ex } // PrimaryBalance returns the balance of the primary store for the owner -func (client *FungibleAssetClient) PrimaryBalance(owner *AccountAddress) (balance uint64, err error) { - val, err := client.viewPrimaryStoreMetadata([][]byte{owner[:], client.metadataAddress[:]}, "balance") +func (client *FungibleAssetClient) PrimaryBalance(owner *AccountAddress, ledgerVersion ...uint64) (balance uint64, err error) { + val, err := client.viewPrimaryStoreMetadata([][]byte{owner[:], client.metadataAddress[:]}, "balance", ledgerVersion...) if err != nil { return } @@ -100,8 +100,8 @@ func (client *FungibleAssetClient) PrimaryBalance(owner *AccountAddress) (balanc } // PrimaryIsFrozen returns true if the primary store for the owner is frozen -func (client *FungibleAssetClient) PrimaryIsFrozen(owner *AccountAddress) (isFrozen bool, err error) { - val, err := client.viewPrimaryStore([][]byte{owner[:], client.metadataAddress[:]}, "is_frozen") +func (client *FungibleAssetClient) PrimaryIsFrozen(owner *AccountAddress, ledgerVersion ...uint64) (isFrozen bool, err error) { + val, err := client.viewPrimaryStore([][]byte{owner[:], client.metadataAddress[:]}, "is_frozen", ledgerVersion...) if err != nil { return } @@ -110,8 +110,8 @@ func (client *FungibleAssetClient) PrimaryIsFrozen(owner *AccountAddress) (isFro } // Balance returns the balance of the store -func (client *FungibleAssetClient) Balance(storeAddress *AccountAddress) (balance uint64, err error) { - val, err := client.viewStore([][]byte{storeAddress[:]}, "balance") +func (client *FungibleAssetClient) Balance(storeAddress *AccountAddress, ledgerVersion ...uint64) (balance uint64, err error) { + val, err := client.viewStore([][]byte{storeAddress[:]}, "balance", ledgerVersion...) if err != nil { return } @@ -120,8 +120,8 @@ func (client *FungibleAssetClient) Balance(storeAddress *AccountAddress) (balanc } // IsFrozen returns true if the store is frozen -func (client *FungibleAssetClient) IsFrozen(storeAddress *AccountAddress) (isFrozen bool, err error) { - val, err := client.viewStore([][]byte{storeAddress[:]}, "is_frozen") +func (client *FungibleAssetClient) IsFrozen(storeAddress *AccountAddress, ledgerVersion ...uint64) (isFrozen bool, err error) { + val, err := client.viewStore([][]byte{storeAddress[:]}, "is_frozen", ledgerVersion...) if err != nil { return } @@ -130,8 +130,8 @@ func (client *FungibleAssetClient) IsFrozen(storeAddress *AccountAddress) (isFro } // IsUntransferable returns true if the store can't be transferred -func (client *FungibleAssetClient) IsUntransferable(storeAddress *AccountAddress) (isFrozen bool, err error) { - val, err := client.viewStore([][]byte{storeAddress[:]}, "is_untransferable") +func (client *FungibleAssetClient) IsUntransferable(storeAddress *AccountAddress, ledgerVersion ...uint64) (isFrozen bool, err error) { + val, err := client.viewStore([][]byte{storeAddress[:]}, "is_untransferable", ledgerVersion...) if err != nil { return } @@ -140,8 +140,8 @@ func (client *FungibleAssetClient) IsUntransferable(storeAddress *AccountAddress } // StoreExists returns true if the store exists -func (client *FungibleAssetClient) StoreExists(storeAddress *AccountAddress) (exists bool, err error) { - val, err := client.viewStore([][]byte{storeAddress[:]}, "store_exists") +func (client *FungibleAssetClient) StoreExists(storeAddress *AccountAddress, ledgerVersion ...uint64) (exists bool, err error) { + val, err := client.viewStore([][]byte{storeAddress[:]}, "store_exists", ledgerVersion...) if err != nil { return } @@ -151,8 +151,8 @@ func (client *FungibleAssetClient) StoreExists(storeAddress *AccountAddress) (ex } // StoreMetadata returns the [AccountAddress] of the metadata for the store -func (client *FungibleAssetClient) StoreMetadata(storeAddress *AccountAddress) (metadataAddress *AccountAddress, err error) { - val, err := client.viewStore([][]byte{storeAddress[:]}, "store_metadata") +func (client *FungibleAssetClient) StoreMetadata(storeAddress *AccountAddress, ledgerVersion ...uint64) (metadataAddress *AccountAddress, err error) { + val, err := client.viewStore([][]byte{storeAddress[:]}, "store_metadata", ledgerVersion...) if err != nil { return } @@ -160,8 +160,8 @@ func (client *FungibleAssetClient) StoreMetadata(storeAddress *AccountAddress) ( } // Supply returns the total supply of the fungible asset -func (client *FungibleAssetClient) Supply() (supply *big.Int, err error) { - val, err := client.viewMetadata([][]byte{client.metadataAddress[:]}, "supply") +func (client *FungibleAssetClient) Supply(ledgerVersion ...uint64) (supply *big.Int, err error) { + val, err := client.viewMetadata([][]byte{client.metadataAddress[:]}, "supply", ledgerVersion...) if err != nil { return } @@ -169,8 +169,8 @@ func (client *FungibleAssetClient) Supply() (supply *big.Int, err error) { } // Maximum returns the maximum possible supply of the fungible asset -func (client *FungibleAssetClient) Maximum() (maximum *big.Int, err error) { - val, err := client.viewMetadata([][]byte{client.metadataAddress[:]}, "maximum") +func (client *FungibleAssetClient) Maximum(ledgerVersion ...uint64) (maximum *big.Int, err error) { + val, err := client.viewMetadata([][]byte{client.metadataAddress[:]}, "maximum", ledgerVersion...) if err != nil { return } @@ -228,7 +228,7 @@ func (client *FungibleAssetClient) ProjectUri(uri string, err error) { } // viewMetadata calls a view function on the fungible asset metadata -func (client *FungibleAssetClient) viewMetadata(args [][]byte, functionName string) (result any, err error) { +func (client *FungibleAssetClient) viewMetadata(args [][]byte, functionName string, ledgerVersion ...uint64) (result any, err error) { payload := &ViewPayload{ Module: ModuleId{ Address: AccountOne, @@ -238,11 +238,11 @@ func (client *FungibleAssetClient) viewMetadata(args [][]byte, functionName stri ArgTypes: []TypeTag{metadataStructTag()}, Args: args, } - return client.view(payload) + return client.view(payload, ledgerVersion...) } // viewStore calls a view function on the fungible asset store -func (client *FungibleAssetClient) viewStore(args [][]byte, functionName string) (result any, err error) { +func (client *FungibleAssetClient) viewStore(args [][]byte, functionName string, ledgerVersion ...uint64) (result any, err error) { payload := &ViewPayload{ Module: ModuleId{ Address: AccountOne, @@ -252,11 +252,11 @@ func (client *FungibleAssetClient) viewStore(args [][]byte, functionName string) ArgTypes: []TypeTag{storeStructTag()}, Args: args, } - return client.view(payload) + return client.view(payload, ledgerVersion...) } // viewPrimaryStore calls a view function on the primary fungible asset store -func (client *FungibleAssetClient) viewPrimaryStore(args [][]byte, functionName string) (result any, err error) { +func (client *FungibleAssetClient) viewPrimaryStore(args [][]byte, functionName string, ledgerVersion ...uint64) (result any, err error) { payload := &ViewPayload{ Module: ModuleId{ Address: AccountOne, @@ -266,11 +266,11 @@ func (client *FungibleAssetClient) viewPrimaryStore(args [][]byte, functionName ArgTypes: []TypeTag{storeStructTag()}, Args: args, } - return client.view(payload) + return client.view(payload, ledgerVersion...) } // viewPrimaryStoreMetadata calls a view function on the primary fungible asset store metadata -func (client *FungibleAssetClient) viewPrimaryStoreMetadata(args [][]byte, functionName string) (result any, err error) { +func (client *FungibleAssetClient) viewPrimaryStoreMetadata(args [][]byte, functionName string, ledgerVersion ...uint64) (result any, err error) { payload := &ViewPayload{ Module: ModuleId{ Address: AccountOne, @@ -280,7 +280,7 @@ func (client *FungibleAssetClient) viewPrimaryStoreMetadata(args [][]byte, funct ArgTypes: []TypeTag{metadataStructTag()}, Args: args, } - return client.view(payload) + return client.view(payload, ledgerVersion...) } func metadataStructTag() TypeTag { @@ -291,8 +291,8 @@ func storeStructTag() TypeTag { return TypeTag{Value: &StructTag{Address: AccountOne, Module: "fungible_asset", Name: "FungibleStore"}} } -func (client *FungibleAssetClient) view(payload *ViewPayload) (result any, err error) { - vals, err := client.aptosClient.View(payload) +func (client *FungibleAssetClient) view(payload *ViewPayload, ledgerVersion ...uint64) (result any, err error) { + vals, err := client.aptosClient.View(payload, ledgerVersion...) if err != nil { return } diff --git a/nodeClient.go b/nodeClient.go index d7c0ea1..7c163c9 100644 --- a/nodeClient.go +++ b/nodeClient.go @@ -974,7 +974,7 @@ func (rc *NodeClient) EstimateGasPrice() (info EstimateGasInfo, err error) { } // AccountAPTBalance fetches the balance of an account of APT. Response is in octas or 1/10^8 APT. -func (rc *NodeClient) AccountAPTBalance(account AccountAddress) (balance uint64, err error) { +func (rc *NodeClient) AccountAPTBalance(account AccountAddress, ledgerVersion ...uint64) (balance uint64, err error) { accountBytes, err := bcs.Serialize(&account) if err != nil { return 0, err @@ -986,7 +986,7 @@ func (rc *NodeClient) AccountAPTBalance(account AccountAddress) (balance uint64, Function: "balance", ArgTypes: []TypeTag{AptosCoinTypeTag}, Args: [][]byte{accountBytes}, - }) + }, ledgerVersion...) if err != nil { return 0, err } From 5606ce97302892671933a182d8b47d4e6a390abb Mon Sep 17 00:00:00 2001 From: GhostWalker562 <43276017+GhostWalker562@users.noreply.github.com> Date: Fri, 22 Nov 2024 11:09:06 -0800 Subject: [PATCH 2/2] Add support for AIP-80 parsing and formatting (#107) Make ToAIP80 return error, fix bytes parsing Co-authored-by: Greg Nazario --- CHANGELOG.md | 1 + crypto/ed25519.go | 14 ++++- crypto/ed25519_test.go | 13 +++-- crypto/privateKey.go | 93 +++++++++++++++++++++++++++++++++ crypto/secp256k1.go | 12 ++++- crypto/secp256k1_test.go | 13 +++-- examples/fungible_asset/main.go | 2 +- 7 files changed, 136 insertions(+), 12 deletions(-) create mode 100644 crypto/privateKey.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f7fe7f..04ad1e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ adheres to the format set out by [Keep a Changelog](https://keepachangelog.com/e # Unreleased +- Add AIP-80 support for Ed25519 and Secp256k1 private keys - Add support for optional ledger version in FA functions and APT balance # v1.2.0 (11/15/2024) diff --git a/crypto/ed25519.go b/crypto/ed25519.go index 5f05ad2..787689a 100644 --- a/crypto/ed25519.go +++ b/crypto/ed25519.go @@ -4,10 +4,11 @@ import ( "crypto/ed25519" "errors" "fmt" + "io" + "github.com/aptos-labs/aptos-go-sdk/bcs" "github.com/aptos-labs/aptos-go-sdk/internal/util" "github.com/hdevalence/ed25519consensus" - "io" ) //region Ed25519PrivateKey @@ -151,6 +152,10 @@ func (key *Ed25519PrivateKey) Bytes() []byte { // Implements: // - [CryptoMaterial] func (key *Ed25519PrivateKey) FromBytes(bytes []byte) (err error) { + bytes, err = ParsePrivateKey(bytes, PrivateKeyVariantEd25519, false) + if err != nil { + return err + } if len(bytes) != ed25519.SeedSize { return fmt.Errorf("invalid ed25519 private key size %d", len(bytes)) } @@ -166,6 +171,11 @@ func (key *Ed25519PrivateKey) ToHex() string { return util.BytesToHex(key.Bytes()) } +// ToAIP80 formats the private key to AIP-80 compliant string +func (key *Ed25519PrivateKey) ToAIP80() (formattedString string, err error) { + return FormatPrivateKey(key.ToHex(), PrivateKeyVariantEd25519) +} + // FromHex sets the [Ed25519PrivateKey] to the bytes represented by the hex string, with or without a leading 0x // // Errors if the hex string is not valid, or if the bytes length is not [ed25519.SeedSize]. @@ -173,7 +183,7 @@ func (key *Ed25519PrivateKey) ToHex() string { // Implements: // - [CryptoMaterial] func (key *Ed25519PrivateKey) FromHex(hexStr string) (err error) { - bytes, err := util.ParseHex(hexStr) + bytes, err := ParsePrivateKey(hexStr, PrivateKeyVariantEd25519) if err != nil { return err } diff --git a/crypto/ed25519_test.go b/crypto/ed25519_test.go index d746091..23324fc 100644 --- a/crypto/ed25519_test.go +++ b/crypto/ed25519_test.go @@ -2,13 +2,15 @@ package crypto import ( "crypto/ed25519" + "testing" + "github.com/aptos-labs/aptos-go-sdk/bcs" "github.com/aptos-labs/aptos-go-sdk/internal/util" "github.com/stretchr/testify/assert" - "testing" ) -const testEd25519PrivateKey = "0xc5338cd251c22daa8c9c9cc94f498cc8a5c7e1d2e75287a5dda91096fe64efa5" +const testEd25519PrivateKey = "ed25519-priv-0xc5338cd251c22daa8c9c9cc94f498cc8a5c7e1d2e75287a5dda91096fe64efa5" +const testEd25519PrivateKeyHex = "0xc5338cd251c22daa8c9c9cc94f498cc8a5c7e1d2e75287a5dda91096fe64efa5" const testEd25519PublicKey = "0xde19e5d1880cac87d57484ce9ed2e84cf0f9599f12e7cc3a52e4e7657a763f2c" const testEd25519Address = "0x978c213990c4833df71548df7ce49d54c759d6b6d932de22b24d56060b7af2aa" const testEd25519Message = "0x68656c6c6f20776f726c64" @@ -18,7 +20,7 @@ func TestEd25519Keys(t *testing.T) { testEd25519PrivateKeyBytes := []byte{0xc5, 0x33, 0x8c, 0xd2, 0x51, 0xc2, 0x2d, 0xaa, 0x8c, 0x9c, 0x9c, 0xc9, 0x4f, 0x49, 0x8c, 0xc8, 0xa5, 0xc7, 0xe1, 0xd2, 0xe7, 0x52, 0x87, 0xa5, 0xdd, 0xa9, 0x10, 0x96, 0xfe, 0x64, 0xef, 0xa5} // First ensure bytes and hex are the same - readBytes, err := util.ParseHex(testEd25519PrivateKey) + readBytes, err := util.ParseHex(testEd25519PrivateKeyHex) assert.NoError(t, err) assert.Equal(t, testEd25519PrivateKeyBytes, readBytes) @@ -33,7 +35,10 @@ func TestEd25519Keys(t *testing.T) { // The outputs should match as well assert.Equal(t, privateKey.Bytes(), testEd25519PrivateKeyBytes) - assert.Equal(t, privateKey.ToHex(), testEd25519PrivateKey) + assert.Equal(t, privateKey.ToHex(), testEd25519PrivateKeyHex) + formattedString, err := privateKey.ToAIP80() + assert.NoError(t, err) + assert.Equal(t, formattedString, testEd25519PrivateKey) // Auth key should match assert.Equal(t, testEd25519Address, privateKey.AuthKey().ToHex()) diff --git a/crypto/privateKey.go b/crypto/privateKey.go new file mode 100644 index 0000000..88cdfe5 --- /dev/null +++ b/crypto/privateKey.go @@ -0,0 +1,93 @@ +package crypto + +import ( + "fmt" + "strings" + + "github.com/aptos-labs/aptos-go-sdk/internal/util" +) + +// PrivateKeyVariant represents the type of private key +type PrivateKeyVariant string + +const ( + PrivateKeyVariantEd25519 PrivateKeyVariant = "ed25519" + PrivateKeyVariantSecp256k1 PrivateKeyVariant = "secp256k1" +) + +// AIP80Prefixes contains the AIP-80 compliant prefixes for each private key type +var AIP80Prefixes = map[PrivateKeyVariant]string{ + PrivateKeyVariantEd25519: "ed25519-priv-", + PrivateKeyVariantSecp256k1: "secp256k1-priv-", +} + +// FormatPrivateKey formats a hex input to an AIP-80 compliant string +func FormatPrivateKey(privateKey any, keyType PrivateKeyVariant) (formattedString string, err error) { + aip80Prefix := AIP80Prefixes[keyType] + + var hexStr string + switch v := privateKey.(type) { + case string: + // Remove the prefix if it exists + if strings.HasPrefix(v, aip80Prefix) { + parts := strings.Split(v, "-") + v = parts[2] + } + + // If it's already a string, just ensure it's properly formatted + var strBytes, err = util.ParseHex(v) + if err != nil { + return "", err + } + + // Reformat to have 0x prefix + hexStr = util.BytesToHex(strBytes) + case []byte: + hexStr = util.BytesToHex(v) + default: + return "", fmt.Errorf("unsupported private key type: must be string or []byte") + } + + return fmt.Sprintf("%s%s", aip80Prefix, hexStr), nil +} + +// ParseHexInput parses a hex input that may be bytes, hex string, or an AIP-80 compliant string to bytes. +// +// You may optionally pass in a boolean to strictly enforce AIP-80 compliance. +func ParsePrivateKey(value any, keyType PrivateKeyVariant, strict ...bool) (bytes []byte, err error) { + aip80Prefix := AIP80Prefixes[keyType] + + // Get the first boolean if it exists, otherwise nil + var strictness *bool = nil + if len(strict) > 1 { + return nil, fmt.Errorf("strictness must be a single boolean") + } else if len(strict) == 1 { + strictness = &strict[0] + } + + switch v := value.(type) { + case string: + if (strictness == nil || !*strictness) && !strings.HasPrefix(v, aip80Prefix) { + bytes, err := util.ParseHex(v) + if err != nil { + return nil, err + } + + // If strictness is not explicitly false, warn about non-AIP-80 compliance + if strictness == nil { + fmt.Printf("[Aptos SDK] It is recommended that private keys are AIP-80 compliant (https://github.com/aptos-foundation/AIPs/blob/main/aips/aip-80.md). You can fix the private key by formatting it with crypto.FormatPrivateKey") + } + + return bytes, nil + } else if strings.HasPrefix(v, aip80Prefix) { + // Parse for AIP-80 compliant String input + parts := strings.Split(v, "-") + return util.ParseHex(parts[2]) + } + return nil, fmt.Errorf("invalid hex string input while parsing private key. Must be AIP-80 compliant string") + case []byte: + return v, nil + default: + return nil, fmt.Errorf("unsupported private key type: must be string or []byte") + } +} diff --git a/crypto/secp256k1.go b/crypto/secp256k1.go index 1dc4868..ab921fd 100644 --- a/crypto/secp256k1.go +++ b/crypto/secp256k1.go @@ -3,6 +3,7 @@ package crypto import ( "crypto/ecdsa" "fmt" + "github.com/aptos-labs/aptos-go-sdk/bcs" "github.com/aptos-labs/aptos-go-sdk/internal/util" ethCrypto "github.com/ethereum/go-ethereum/crypto" @@ -98,6 +99,10 @@ func (key *Secp256k1PrivateKey) Bytes() []byte { // Implements: // - [CryptoMaterial] func (key *Secp256k1PrivateKey) FromBytes(bytes []byte) (err error) { + bytes, err = ParsePrivateKey(bytes, PrivateKeyVariantSecp256k1, false) + if err != nil { + return err + } if len(bytes) != Secp256k1PrivateKeyLength { return fmt.Errorf("invalid secp256k1 private key size %d", len(bytes)) } @@ -117,6 +122,11 @@ func (key *Secp256k1PrivateKey) ToHex() string { return util.BytesToHex(key.Bytes()) } +// ToAIP80 formats the private key to AIP-80 compliant string +func (key *Secp256k1PrivateKey) ToAIP80() (formattedString string, err error) { + return FormatPrivateKey(key.ToHex(), PrivateKeyVariantSecp256k1) +} + //endregion // FromHex populates the [Secp256k1PrivateKey] from a hex string @@ -126,7 +136,7 @@ func (key *Secp256k1PrivateKey) ToHex() string { // Implements: // - [CryptoMaterial] func (key *Secp256k1PrivateKey) FromHex(hexStr string) (err error) { - bytes, err := util.ParseHex(hexStr) + bytes, err := ParsePrivateKey(hexStr, PrivateKeyVariantSecp256k1) if err != nil { return err } diff --git a/crypto/secp256k1_test.go b/crypto/secp256k1_test.go index 0d8322f..6f70d6e 100644 --- a/crypto/secp256k1_test.go +++ b/crypto/secp256k1_test.go @@ -1,14 +1,16 @@ package crypto import ( + "testing" + "github.com/aptos-labs/aptos-go-sdk/bcs" "github.com/aptos-labs/aptos-go-sdk/internal/util" "github.com/stretchr/testify/assert" - "testing" ) const ( - testSecp256k1PrivateKey = "0xd107155adf816a0a94c6db3c9489c13ad8a1eda7ada2e558ba3bfa47c020347e" + testSecp256k1PrivateKey = "secp256k1-priv-0xd107155adf816a0a94c6db3c9489c13ad8a1eda7ada2e558ba3bfa47c020347e" + testSecp256k1PrivateKeyHex = "0xd107155adf816a0a94c6db3c9489c13ad8a1eda7ada2e558ba3bfa47c020347e" testSecp256k1PublicKey = "0x04acdd16651b839c24665b7e2033b55225f384554949fef46c397b5275f37f6ee95554d70fb5d9f93c5831ebf695c7206e7477ce708f03ae9bb2862dc6c9e033ea" testSecp256k1Address = "0x5792c985bc96f436270bd2a3c692210b09c7febb8889345ceefdbae4bacfe498" testSecp256k1MessageEncoded = "0x68656c6c6f20776f726c64" @@ -16,7 +18,7 @@ const ( ) func TestSecp256k1Keys(t *testing.T) { - testSecp256k1PrivateKeyBytes, err := util.ParseHex(testSecp256k1PrivateKey) + testSecp256k1PrivateKeyBytes, err := util.ParseHex(testSecp256k1PrivateKeyHex) assert.NoError(t, err) // Either bytes or hex should work @@ -30,7 +32,10 @@ func TestSecp256k1Keys(t *testing.T) { // The outputs should match as well assert.Equal(t, privateKey.Bytes(), testSecp256k1PrivateKeyBytes) - assert.Equal(t, privateKey.ToHex(), testSecp256k1PrivateKey) + assert.Equal(t, privateKey.ToHex(), testSecp256k1PrivateKeyHex) + formattedString, err := privateKey.ToAIP80() + assert.NoError(t, err) + assert.Equal(t, formattedString, testSecp256k1PrivateKey) // Auth key should match singleSender := SingleSigner{privateKey} diff --git a/examples/fungible_asset/main.go b/examples/fungible_asset/main.go index 182efc9..09c8c3c 100644 --- a/examples/fungible_asset/main.go +++ b/examples/fungible_asset/main.go @@ -9,7 +9,7 @@ import ( "github.com/aptos-labs/aptos-go-sdk/crypto" ) -const testEd25519PrivateKey = "0xc5338cd251c22daa8c9c9cc94f498cc8a5c7e1d2e75287a5dda91096fe64efa5" +const testEd25519PrivateKey = "ed25519-priv-0xc5338cd251c22daa8c9c9cc94f498cc8a5c7e1d2e75287a5dda91096fe64efa5" const rupeePublisherAddress = "0x978c213990c4833df71548df7ce49d54c759d6b6d932de22b24d56060b7af2aa" // These come from fungible_asset.json