Skip to content

feat: add plugin-owned primitive registry and firmware-gated reqs#728

Open
yilmazbahadir wants to merge 4 commits intodevfrom
baha/feat/primitive-registry
Open

feat: add plugin-owned primitive registry and firmware-gated reqs#728
yilmazbahadir wants to merge 4 commits intodevfrom
baha/feat/primitive-registry

Conversation

@yilmazbahadir
Copy link
Collaborator

@yilmazbahadir yilmazbahadir commented Feb 25, 2026

📝 Summary

This PR implements a plugin-owned primitive registry so adding/migrating chains no longer requires broad SDK helper coupling.

It introduces primitive definitions/requirements on chain plugins, migrates current Lattice signers (evm, solana, cosmos, xrp) to runtime primitive resolution, and enforces explicit firmware gating via minFirmware (no baseline shorthand).

🔧 Context / Implementation

  • Added primitive model to chain-core:
    • PrimitiveKind, PrimitiveDefinition, PrimitiveRequirement, PluginPrimitives
    • primitives?: PluginPrimitives on ChainPlugin
  • Added new chain-core primitive registry with:
    • createPrimitiveRegistry, preflight, atomic register, resolve, resolveOrThrow, reverseResolve, has, list, reset (test isolation)
    • collision semantics for name/code conflicts
  • Added SDK primitive lifecycle module:
    • lazy/idempotent seeding from EXTERNAL.SIGNING.{HASHES,CURVES,ENCODINGS}
    • plugin primitive preflight/register helpers
    • fail-closed requirement validation requiring explicit minFirmware
  • Updated chain runtime registration flow to be transactional:
    • seed primitives -> preflight defs -> register chain -> commit defs
    • rollback chain registration if primitive commit fails
    • discovery path now uses the same registration flow
  • Added runtime firmware requirement enforcement in useChain() before signer creation.
  • Updated setup flow to seed primitives early (still idempotent).
  • Migrated lattice signers (evm, solana, cosmos, xrp) to context.resolvePrimitive(...) for signing primitive codes.
  • Added plugin primitive requirements:
    • EVM: SECP256K1, KECCAK256, EVM
    • Solana: ED25519, NONE, SOLANA
    • Cosmos: SECP256K1, SHA256, COSMOS
    • XRP: SECP256K1, SHA512HALF, XRP
  • Added explicit request-time EIP-7702 firmware gate in EVM signer (min firmware: 0.18.0).
  • Kept GET_ADDR_FLAGS and existing getFwVersionConst() behavior unchanged in this PR.

Concrete developer experience — what a new chain plugin author writes:

export const latticePlugin: ChainPlugin<LatticeNewChainContext> = {
  chainId: 'newchain',
  device: 'lattice',
  module: newchain,
  createSigner: (context) => createLatticeNewChainSigner(context),
  primitives: {
    // Only include definitions for primitives that are not already seeded by SDK built-ins.
    definitions: [
      { kind: 'encoding', name: 'NEWCHAIN', code: 9 },
      { kind: 'hash', name: 'BLAKE2B', code: 4 },
    ],
    // Every requirement must use explicit minFirmware (no baseline field).
    requirements: [
      { kind: 'curve', name: 'ED25519', minFirmware: [0, 14, 0] },
      { kind: 'encoding', name: 'NEWCHAIN', minFirmware: [0, 20, 0] },
      { kind: 'hash', name: 'BLAKE2B', minFirmware: [0, 20, 0] },
    ],
  },
};

// Inside the signer: resolve codes via context (throws if missing).
const curveCode = context.resolvePrimitive('curve', 'ED25519');
const encodingCode = context.resolvePrimitive('encoding', 'NEWCHAIN');
const hashCode = context.resolvePrimitive('hash', 'BLAKE2B');

🧪 Test Plan

  1. Run type checks:
    • pnpm --filter @gridplus/chain-core typecheck
    • pnpm --filter gridplus-sdk typecheck
  2. Run SDK unit tests:
    • pnpm --filter gridplus-sdk test-unit
  3. Verify targeted behavior:
    • primitive registry collision/preflight/atomic semantics
    • lazy seeding + requirement validation (pass/fail paths)
    • transactional chain registration + no partial state on failure
    • signer primitive resolution for EVM/Solana/Cosmos/XRP
    • EVM EIP-7702 request-time firmware gating

Expected result: all commands pass, registration remains fail-safe/transactional, and signer payloads resolve primitive codes via registry with correct firmware gating behavior.

🖼️ Screenshots (if applicable)

Before After
N/A N/A

…ents

Migrate EVM/Solana/Cosmos/XRP lattice signers to resolve primitives via registry, add transactional chain registration, and extend unit test coverage.
@yilmazbahadir yilmazbahadir changed the title feat: add plugin-owned primitive registry and firmware-gated requirem… feat: add plugin-owned primitive registry and firmware-gated reqs Feb 25, 2026
@yilmazbahadir yilmazbahadir force-pushed the baha/feat/primitive-registry branch from 70f9fae to a83c402 Compare February 25, 2026 13:44
@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 25, 2026

Open in StackBlitz

npm i https://pkg.pr.new/GridPlus/gridplus-sdk@728

commit: b06f89d

@yilmazbahadir yilmazbahadir marked this pull request as ready for review February 25, 2026 20:52
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d308cf86e2

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

…imitives on unregister

Add lattice signer fallback to EXTERNAL.SIGNING when resolvePrimitive is absent, and remove plugin-owned primitive definitions during unregisterChain to prevent stale conflicts.
@yilmazbahadir yilmazbahadir requested a review from hmrkx February 25, 2026 21:36
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.

1 participant