Skip to content

Add v2 import_private_key example - #141

Merged
truham merged 2 commits into
mainfrom
hamilton/migrate-import-private-key-example
Aug 26, 2026
Merged

truham merged 2 commits into
mainfrom
hamilton/migrate-import-private-key-example

Conversation

@truham

@truham truham commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Summary & Motivation

Migrate the private_keys/import_private_key example from v1 (v0.17.0) to the v2 SDK.

  • Use the v2 client API (NewAPIKeyStamper / NewClient) and flat request structs in place of the v1 pointer-heavy models
  • Replace manual hex/base58 decoding and enclave-encrypt setup with crypto.EncryptPrivateKeyToBundle
  • Read config from environment variables, consistent with the other v2 examples
  • Support both Secp256k1 (Ethereum, hex) and Ed25519 (Solana, base58) keys

Also adds a private_keys README and lists the example in examples/README.md

How I Tested These Changes

Ran the example end-to-end against a live org, importing a private key exported from MetaMask. Confirmed it returns a private key ID and that the derived address matches the source account. Also verified the duplicate-import path surfaces a clean 409 error.

Did you add a changeset?

No changeset required — this only adds an example and does not change SDK behavior.

truham and others added 2 commits July 30, 2026 14:55
Migrate the private_keys/import_private_key example from v1 (v0.17.0)
to the v2 SDK.

- Use the v2 client API (NewAPIKeyStamper / NewClient) and flat request
  structs in place of the v1 pointer-heavy models.
- Replace manual hex/base58 decoding and enclave-encrypt setup with
  crypto.EncryptPrivateKeyToBundle.
- Read config from environment variables, consistent with the other
  v2 examples.
- Support both Secp256k1 (Ethereum, hex) and Ed25519 (Solana, base58)
  keys.

Add a private_keys README and list the example in examples/README.md.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Extract key selection and address printing into selectKey and
printAddresses helpers so main's cyclomatic complexity is under the
gocyclo threshold (was 13, limit 10). Behavior is unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@t-vila t-vila left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm !

@truham
truham merged commit 5dba963 into main Aug 26, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants