-
Notifications
You must be signed in to change notification settings - Fork 26
feat: new session keys with viem #618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
609eb74
feat: new session keys support
hugomrdias 2d6fef5
chore: remove old sessions from react
hugomrdias 0494576
chore: cli testing
hugomrdias adc3d6d
feat: use hash based enum like session key permissions instead of str…
hugomrdias 8ba72b0
feat: wire back session keys
hugomrdias 7fdc04d
refactor: update session key handling to use watch/unwatch methods an…
hugomrdias File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import * as p from '@clack/prompts' | ||
| import * as SessionKey from '@filoz/synapse-core/session-key' | ||
| import { createDataSet, waitForCreateDataSet } from '@filoz/synapse-core/sp' | ||
| import { type Command, command } from 'cleye' | ||
| import { type Hex, stringify } from 'viem' | ||
| import { privateKeyClient } from '../client.ts' | ||
| import { globalFlags } from '../flags.ts' | ||
| import { hashLink } from '../utils.ts' | ||
|
|
||
| export const sessionKeys: Command = command( | ||
| { | ||
| name: 'session-keys', | ||
| description: 'Manage session keys', | ||
| alias: 'sk', | ||
| flags: { | ||
| ...globalFlags, | ||
| }, | ||
| help: { | ||
| description: 'Manage session keys', | ||
| }, | ||
| }, | ||
| async (argv) => { | ||
| const { client, chain } = privateKeyClient(argv.flags.chain) | ||
| const sessionKey = SessionKey.fromSecp256k1({ | ||
| privateKey: | ||
| '0xaa14e25eaea762df1533e72394b85e56dd0c7aa61cf6df3b1f13a842ca0361e5' as Hex, | ||
| root: client.account, | ||
| chain, | ||
| }) | ||
|
|
||
| p.log.info(`Root address: ${sessionKey.account.rootAddress}`) | ||
| p.log.info(`Session key address: ${sessionKey.account.address}`) | ||
|
|
||
| sessionKey.on('expirationsUpdated', (e) => { | ||
| p.log.warn('Expirations updated', e.detail) | ||
| }) | ||
| sessionKey.on('connected', (e) => { | ||
| p.log.success('Connected', e.detail) | ||
| }) | ||
| sessionKey.on('disconnected', () => { | ||
| p.log.warn('Disconnected') | ||
| }) | ||
| sessionKey.on('error', (e) => { | ||
| p.log.error(e.detail.message) | ||
| }) | ||
|
|
||
| const { event: loginEvent } = await SessionKey.loginSync(client, { | ||
| address: sessionKey.address, | ||
| onHash(hash) { | ||
| p.log.step(`Waiting for tx ${hashLink(hash, chain)} to be mined...`) | ||
| }, | ||
| }) | ||
| p.log.success(`Login event: ${stringify(loginEvent.args)}`) | ||
|
|
||
| await sessionKey.watch() | ||
|
|
||
| if (sessionKey.hasPermission(SessionKey.CreateDataSetPermission)) { | ||
| const result = await createDataSet(sessionKey.client, { | ||
| payee: '0xa3971A7234a3379A1813d9867B531e7EeB20ae07', | ||
| payer: sessionKey.rootAddress, | ||
| serviceURL: 'https://calib.ezpdpz.net', | ||
| cdn: false, | ||
| }) | ||
| p.log.step( | ||
| `Waiting for tx ${hashLink(result.txHash, chain)} to be mined...` | ||
| ) | ||
| const dataset = await waitForCreateDataSet(result) | ||
| p.log.success(`Data set created #${dataset.dataSetId}`) | ||
| } else { | ||
| p.log.error('Session key does not have permission to create data set') | ||
| } | ||
|
|
||
| const { event: revokeEvent } = await SessionKey.revokeSync(client, { | ||
| address: sessionKey.address, | ||
| onHash(hash) { | ||
| p.log.step(`Waiting for tx ${hashLink(hash, chain)} to be mined...`) | ||
| }, | ||
| }) | ||
| p.log.success(`Revoke event: ${stringify(revokeEvent.args)}`) | ||
| sessionKey.unwatch() | ||
| } | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.