Skip to content
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

Add P-Chain address derivation support #118

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

xiaoxiaff
Copy link

@xiaoxiaff xiaoxiaff commented May 26, 2022

This PR adds support for P-Chain address derivation.

The P chain network identifier will be:

&types.NetworkIdentifier{
		Blockchain: service.BlockchainName,
		Network:    cfg.NetworkName,
		SubNetworkIdentifier: &types.SubNetworkIdentifier{
			Network: "P",
		},
	}

Test:

curl --data '{"network_identifier"
:{"blockchain":"Avalanche","network":"Fuji", "sub_network_identifier":
{"network":"P"}},"public_key":{"hex_bytes":"02d95fcfa4321a1291bd8b3876
35fe0c3b9fa6d243153387fbe298a467b0c2ab32","curve_type":"secp256r1"}}' --header "Content-Type: application/json" --request POST 0.0.0.0:8080/construction/derive | jq .

{
  "address": "P-fuji1s8rrueqvga8597f0nks60m9urtxutw98rx9rdu",
  "account_identifier": {
    "address": "P-fuji1s8rrueqvga8597f0nks60m9urtxutw98rx9rdu"
  }
}

This change is backward compatible since it only derive P-chain address for P-chain request.

Will update test cases once core functionality and structure has been reviewed.

assert.Nil(t, err)
assert.Equal(
t,
"P-fuji15f9g0h5xkr5cp47n6u3qxj6yjtzzzrdr23a3tl",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how I verified the derivation:

	keyData, err := keychain.ParsePrivateKeyAndDeriveAddresses(wc.runtimeConfig.NetworkConfig, privateKeyString)
	if err != nil {
		return err
	}

	println("Private Key           :", keyData.PrivateKey.String())
	println("Public Key            :", hex.EncodeToString(keyData.PublicKey.Bytes()))
	println("P Chain Bech32 Address   :", keyData.Addresses.P)

Result:

Private Key           : PrivateKey-2aazcWnVv1MicvTkqBhjuCkuhE6jdAN4tkXXMHyucKCzEQrNKm
Public Key            : 02e0d4392cfa224d4be19db416b3cf62e90fb2b7015e7b62a95c8cb490514943f6
P Chain Bech32 Address   : P-fuji15f9g0h5xkr5cp47n6u3qxj6yjtzzzrdr23a3tl

go.sum Outdated Show resolved Hide resolved
cmd/server/main.go Outdated Show resolved Hide resolved
Copy link
Contributor

@StephenButtolph StephenButtolph left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just nits, overall lgtm

mapper/helper.go Outdated Show resolved Hide resolved
mapper/helper.go Outdated Show resolved Hide resolved
mapper/helper.go Outdated Show resolved Hide resolved
mapper/helper.go Outdated Show resolved Hide resolved
cmd/server/main.go Outdated Show resolved Hide resolved
@xiaoxiaff
Copy link
Author

@StephenButtolph fixed comments and rebase the master.

mapper/helper.go Outdated Show resolved Hide resolved
mapper/helper.go Outdated Show resolved Hide resolved
@patrick-ogrady
Copy link
Contributor

We are going to merge something in to pchain-support branch instead of master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants