feat(ts): unified createSigner factory, config union, and resolveAddress#91
feat(ts): unified createSigner factory, config union, and resolveAddress#91
Conversation
Greptile SummaryThis PR adds three new exports to the Confidence Score: 5/5Safe to merge — all remaining findings are P2 style/test-hygiene suggestions with no impact on runtime correctness. The core logic is sound: the discriminated union has no field conflicts, the exhaustive switch provides compile-time coverage, and assertIsAddress guards runtime address validity. Both findings are P2 — a missing beforeEach reset in one test file (tests still pass due to deterministic ordering) and inconsistent await usage that has no behavioral difference without a surrounding try/catch. typescript/packages/keychain/src/tests/resolve-address.test.ts — missing mock reset could make tests fragile if reordered. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["createSigner(config)\nor resolveAddress(config)"] --> B{config.backend}
B -->|aws-kms| C1["resolveAddress: return config.publicKey\ncreateAwsKmsSigner(stripBackend)"]
B -->|gcp-kms| C2["resolveAddress: return config.publicKey\ncreateGcpKmsSigner(stripBackend)"]
B -->|turnkey| C3["resolveAddress: return config.publicKey\ncreateTurnkeySigner(stripBackend)"]
B -->|vault| C4["resolveAddress: return config.publicKey\ncreateVaultSigner(stripBackend)"]
B -->|cdp| C5["resolveAddress: return config.address\ncreateCdpSigner(stripBackend)"]
B -->|crossmint| D1["createCrossmintSigner → signer.address"]
B -->|dfns| D2["createDfnsSigner → signer.address"]
B -->|fireblocks| D3["createFireblocksSigner → signer.address"]
B -->|para| D4["createParaSigner → signer.address"]
B -->|privy| D5["createPrivySigner → signer.address"]
B -->|unknown| E["throwSignerError(CONFIG_ERROR)"]
subgraph Sync["Sync — address in config (no network call)"]
C1
C2
C3
C4
C5
end
subgraph Async["Async — address fetched from remote API"]
D1
D2
D3
D4
D5
end
Reviews (1): Last reviewed commit: "docs(ts): update @solana/keychain README..." | Re-trigger Greptile |
typescript/packages/keychain/src/__tests__/resolve-address.test.ts
Outdated
Show resolved
Hide resolved
… type Closes TOO-240, TOO-241
Returns the signer address without full signing setup. Sync backends (AWS KMS, CDP, GCP KMS, Turnkey, Vault) return the config-provided address directly. Async backends fall back to createSigner(). Closes TOO-242
…union Address review feedback: call assertIsAddress() instead of bare casts in resolveAddress sync branches. Derive BackendName from KeychainSignerConfig to prevent drift.
- Add @solana/addresses as direct dependency (was transitive-only) - Replace raw Error with throwSignerError(CONFIG_ERROR) + never exhaustiveness check in default branches - Add table-driven tests for createSigner (31 tests) and resolveAddress (13 tests) covering all 10 backends
Lead with createSigner/resolveAddress, add missing backends to table (CDP, Dfns, GCP KMS), document KeychainSignerConfig and BackendName.
0042e42 to
bfe9894
Compare
Change @solana/addresses from ^6.0.1 to >=6.0.1 to match the peerDependencies specifier and existing lockfile. Apply prettier formatting to test files.
The dependency was added as ^6.0.1 but the lockfile still had the peerDependencies specifier >=6.0.1. Regenerate lockfile to match.
…ified factory Align contributor-facing docs with PR #72 (audit remediations) and PR #91 (unified createSigner factory): - Replace sign_partial_transaction with SignTransactionResult enum - Add HTTPS enforcement, HTTP timeout, and HttpClientConfig patterns - Add TransactionUtil shared helpers (classify, add_signature, serialize) - Document error redaction, sanitizeRemoteErrorResponse, safe JSON parsing - Expand TS umbrella package section from 3 to 6 integration files - Update security best practices (zeroize, Option<Pubkey>, no .expect())
…ory (#96) * docs: update add-signer guide and skill for audit remediations and unified factory Align contributor-facing docs with PR #72 (audit remediations) and PR #91 (unified createSigner factory): - Replace sign_partial_transaction with SignTransactionResult enum - Add HTTPS enforcement, HTTP timeout, and HttpClientConfig patterns - Add TransactionUtil shared helpers (classify, add_signature, serialize) - Document error redaction, sanitizeRemoteErrorResponse, safe JSON parsing - Expand TS umbrella package section from 3 to 6 integration files - Update security best practices (zeroize, Option<Pubkey>, no .expect()) * fix(docs): remove unused Duration import, add missing http_config param to test templates
Some helpers for our
@solana/keychainumprella package for projects that plan to enable many signers.Summary
createSigner(config)— unified factory that dispatches to the correct backend based on abackenddiscriminant fieldKeychainSignerConfigdiscriminated union type andBackendNamestring literal union for config managementresolveAddress(config)— lightweight address lookup that skips full signer init for backends with the public key in configMotivated by jup-ag/cli#13 where consumers hand-roll the same dispatch logic.
Before (what consumers build today)
After
Config management
Test plan
createSignerandresolveAddresspnpm run build— cleanpnpm run lint— cleanpnpm run typecheck— cleanagadootreeshakability — passesnevercheck in default branches — compile-time failure if a backend is added to the union but not handledCloses TOO-240, TOO-241, TOO-242