Skip to content

[nodes] Add support for optional variablePdaSeedNode #199

Description

@febo

It might be interesting to support optional values on PDA seeds, e.g.:

k.pdaNode({
  name: "account",
  seeds: [
    k.variablePdaSeedNode(
      "from",
      k.publicKeyTypeNode(),
      "Funding account"
    ),
    k.variablePdaSeedNode(
      "seed",
      k.fixedSizeTypeNode(k.bytesTypeNode(), 32),
      "Optional seed for the account derivation"
    ),
    k.variablePdaSeedNode(
      "group",
      k.numberTypeNode("u64"),
      "Group ID for the address derivation"
    ),
  ],
})

In this example, the seed value is optional – it can either be present or not. This would result in the following AccountSeeds for the findAccountPda helper:

export type AccountSeeds = {
  /** Funding account */
  from: Address;
  /** Optional seed for the account derivation */
  seed?: ReadonlyUint8Array;
  /** Group ID for the address derivation */
  group: number | bigint;
};

You could also combine this with default value support (#107), so you could have optional seed values with a default value if one is not provided.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions