Skip to content

Fail to generate solana address from xpub #41

@atlaschiew

Description

@atlaschiew

hi my code is very simple

defmodule Main do
  # Import block_keys functions if needed
  alias BlockKeys

  def run do
    # Example 1: Generate a random mnemonic
    root_key = BlockKeys.from_mnemonic("nurse grid sister metal flock choice system control about mountain sister rapid hundred render shed chicken print cover tape sister zero bronze tattoo stairs")

    IO.puts(root_key)
    # IO.inspect(keypair)

    %{mnemonic: mnemonic, root_key: root_key} = BlockKeys.generate()
    IO.puts(mnemonic)

    path = "M/501'/0'/0'"
    xpub = BlockKeys.CKD.derive(root_key, path, curve: :ed25519)
    IO.puts(xpub)
    IO.puts(root_key)

    address = BlockKeys.Solana.address(xpub, "M/0/0")
    #IO.puts(address)
  end
end

# Call the run function when executing the script
Main.run()

run and then i hit error below

== Compilation error in file lib/main.ex ==
** (MatchError) no match of right hand side value:

    <<13, 127, 151, 139, 214, 158, 144, 138, 145, 174, 99, 133, 107, 102, 79, 221,
      214, 4, 237, 160, 34, 91, 244, 2, 2, 26, 95, 151, 205, 44, 8, 153, 22, 221,
      241, 58, 9, 230, 149, 74, 167, 222, 82, 116, 92, 134, 243, 200, 93, 196, 111,
      248, 63, 248, 103, 243, 218, 4, 184, 115, 135, 158, 204, 192, 140, 75, 196,
      214, 122, 30, 114, 197, 72, 116, 105, 231, 248, 51, 100, 100, 141, 96, 87,
      108>>

    (block_keys 1.0.2) lib/block_keys/encoding.ex:32: BlockKeys.Encoding.decode_extended_key/1
    (block_keys 1.0.2) lib/block_keys/ckd.ex:70: BlockKeys.CKD.child_key_public/2
    (block_keys 1.0.2) lib/block_keys/ckd.ex:57: BlockKeys.CKD._derive/2
    (block_keys 1.0.2) lib/block_keys/solana/solana.ex:10: BlockKeys.Solana.address/2
    lib/main.ex:26: (file)

please help

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions