diff --git a/bin.js b/bin.js index 26125ee..97867b0 100755 --- a/bin.js +++ b/bin.js @@ -25,6 +25,7 @@ import { usageReport, getPlan, createKey, + reset, } from './index.js' import { storeAdd, @@ -305,6 +306,11 @@ cli .option('--json', 'output as json') .action(createKey) +cli + .command('reset') + .describe('Remove all proofs/delegations from the store but retain the agent DID.') + .action(reset) + // show help text if no command provided cli.command('help [cmd]', 'Show help text', { default: true }).action((cmd) => { try { diff --git a/index.js b/index.js index f87bd01..322be88 100644 --- a/index.js +++ b/index.js @@ -10,9 +10,11 @@ import { CarWriter } from '@ipld/car' import { filesFromPaths } from 'files-from-path' import * as Account from './account.js' import { spaceAccess } from '@web3-storage/w3up-client/capability/access' +import { AgentData } from '@web3-storage/access' import * as Space from './space.js' import { getClient, + getStore, checkPathsExist, filesize, filesizeMB, @@ -650,3 +652,15 @@ export async function createKey({ json }) { console.log(key) } } + +export const reset = async () => { + const store = getStore() + const exportData = await store.load() + if (exportData) { + let data = AgentData.fromExport(exportData) + // do not reset the principal + data = await AgentData.create({ principal: data.principal, meta: data.meta }) + await store.save(data.export()) + } + console.log('⁂ Agent reset.') +} diff --git a/lib.js b/lib.js index 24cc359..25b2a0b 100644 --- a/lib.js +++ b/lib.js @@ -57,11 +57,16 @@ export function filesizeMB(bytes) { return `${(bytes / 1000 / 1000).toFixed(1)}MB` } +/** Get a configured w3up store used by the CLI. */ +export function getStore() { + return new StoreConf({ profile: process.env.W3_STORE_NAME ?? 'w3cli' }) +} + /** * Get a new API client configured from env vars. */ export function getClient() { - const store = new StoreConf({ profile: process.env.W3_STORE_NAME ?? 'w3cli' }) + const store = getStore() if (process.env.W3_ACCESS_SERVICE_URL || process.env.W3_UPLOAD_SERVICE_URL) { console.warn(