feat: create session keys with filecoin-pin#215
Conversation
|
It's nice that we have this if it's useful. We aren't prioritizing landing it at the moment. There is probably a discussion on whether it belongs in synapse rather than here. But this starts the conversation. Slack context: https://filecoinproject.slack.com/archives/C07CGTXHHT4/p1762468737807959 |
SgtPooki
left a comment
There was a problem hiding this comment.
super quick self review
|
|
||
| // Step 1: Generate new session key | ||
| onProgress?.('Generating new session key...', {}) | ||
| const sessionWallet = Wallet.createRandom() |
There was a problem hiding this comment.
should we accept a wallet/key as option if someone has a wallet they want to grant permissions to?
There was a problem hiding this comment.
As a stretch goal, sure, the nice thing about accepting someone's wallet is that they could use their existing non-Filecoin wallet to do this. It's one of the things we're exploring with the 8004 work - let them use their Ethereum wallet on Ethereum, but also let it be a session key for Filecoin interactions against an existing wallet that gives them access.
There was a problem hiding this comment.
this is added now, but it's currently under the session create command instead of.. session create-from-existing-wallet or something.
| /** | ||
| * Progress callback for logging/UI updates | ||
| */ | ||
| onProgress?: (step: string, details?: Record<string, string>) => void |
There was a problem hiding this comment.
onprogress should emit typed object with well-known "type" and use our ProgressEvent and ProgressEventHandler types from src/core/utils/types.ts
| export function formatSessionKeyOutput(result: SessionKeyResult): string { | ||
| const expiryDate = new Date(result.expiry * 1000).toISOString().replace('T', ' ').split('.')[0] | ||
|
|
||
| return ` | ||
| ========================================== | ||
| Session key created successfully! | ||
| ========================================== | ||
| Validity: ${result.validityDays} days (expires: ${expiryDate}) | ||
|
|
||
| Add these to your .env file: | ||
| ------------------------------------------ | ||
| WALLET_ADDRESS=${result.ownerWallet.address} | ||
| SESSION_KEY=${result.sessionWallet.privateKey} | ||
|
|
||
| Session key info (for debugging): | ||
| ------------------------------------------ | ||
| SESSION_KEY_ADDRESS=${result.sessionWallet.address} | ||
| OWNER_ADDRESS=${result.ownerWallet.address} | ||
| REGISTRY=${result.registryAddress} | ||
| EXPIRY=${result.expiry} | ||
| `.trim() | ||
| } |
There was a problem hiding this comment.
should not have display details in src/core
| const createCommand = new Command('create') | ||
| .description('Create and authorize a new session key') | ||
| .option('--validity-days <days>', 'Number of days the session key should be valid', '10') | ||
| .action(async (options) => { |
There was a problem hiding this comment.
action logic should be elsewhere: src/session for now, eventually packages/cli or wherever when/if we monorepo
| import { createSessionKey, formatSessionKeyOutput } from '../core/session/create-session-key.js' | ||
| import { addAuthOptions } from '../utils/cli-options.js' | ||
|
|
||
| export const sessionCommand = new Command('session').description( |
There was a problem hiding this comment.
maybe wallet or auth ?
Add filecoin-pin session create CLI command
Converts the bash script debug/create-session.sh to a native TypeScript CLI command for creating session keys.
Changes
Features
Usage
Create session key with default 10-day validity
PRIVATE_KEY=0x... filecoin-pin session create
Custom validity period
PRIVATE_KEY=0x... filecoin-pin session create --validity-days 30
Notes
uses 3)
Example use