Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changelog/accounts-store-owner.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
wallet-cli: patch
---

Delegated CLI wallet persistence and access-key selection to the Accounts SDK while retaining legacy `keys.toml` migration.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
### Minor Changes

- Added access key limit updates and moved key listing from `keys` to `keys list`.

```diff
-tempo wallet keys
+tempo wallet keys list
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@
"test": "vitest run"
},
"dependencies": {
"accounts": "0.16.0",
"accounts": "https://pkg.pr.new/tempoxyz/accounts@1d58599",
"incur": "0.4.8",
"koffi": "3.1.2",
"mppx": "0.8.9",
"undici": "8.5.0",
"viem": "2.54.0"
Expand Down
156 changes: 151 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@ onlyBuiltDependencies:

allowBuilds:
esbuild: true
koffi: true

supportedArchitectures:
os: [darwin, linux]
cpu: [arm64, x64]

minimumReleaseAge: 1440
1 change: 1 addition & 0 deletions scripts/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ run("esbuild", [
"--platform=node",
"--format=cjs",
"--target=node22",
"--external:koffi",
`--define:process.env.TEMPO_WALLET_VERSION=${JSON.stringify(version)}`,
`--outfile=${bundlePath}`,
]);
Expand Down
24 changes: 11 additions & 13 deletions src/commands/identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export async function updateAccessKeyHandler(
"No access key configured for the current wallet and network. Run 'tempo wallet login'.",
);

const token = options.token ?? key.limits[0]?.token ?? tokenAddress(selectedChainId);
const token = options.token ?? key.limits?.[0]?.token ?? tokenAddress(selectedChainId);
if (!isAddress(token)) throw usageError("Invalid token address: expected a 0x address");
const limit = parseLimit(options.limit);
const walletAddress = activeAccount.address as Address;
Expand All @@ -197,16 +197,14 @@ export async function updateAccessKeyHandler(

const accessKeys = state.accessKeys.map((candidate) => {
if (candidate !== key) return candidate;
const existing = candidate.limits.findIndex(
const currentLimits = candidate.limits ?? [];
const existing = currentLimits.findIndex(
(item) => item.token.toLowerCase() === tokenAddress_resolved.toLowerCase(),
);
const nextLimit = `${limit}#__bigint`;
const limits =
existing === -1
? [...candidate.limits, { token: tokenAddress_resolved, limit: nextLimit }]
: candidate.limits.map((item, index) =>
index === existing ? { ...item, limit: nextLimit } : item,
);
? [...currentLimits, { token: tokenAddress_resolved, limit }]
: currentLimits.map((item, index) => (index === existing ? { ...item, limit } : item));
return { ...candidate, limits };
});
await saveWalletState({ ...state, accessKeys });
Expand Down Expand Up @@ -386,7 +384,7 @@ export async function currentWhoamiOutput(options: {
network?: string | undefined;
}) {
const token =
options.accessKeys[0]?.limits[0]?.token ??
options.accessKeys[0]?.limits?.[0]?.token ??
tokenAddress(options.chain ?? chainId(options.network));
const balance = await tokenBalance({
token,
Expand Down Expand Up @@ -419,7 +417,7 @@ export async function currentKeysOutput(options: {
const balances = new Map<string, TokenBalance | null>();
const keys = [];
for (const key of options.accessKeys) {
const token = key.limits[0]?.token ?? tokenAddress(key.chainId);
const token = key.limits?.[0]?.token ?? tokenAddress(key.chainId);
const balance = balances.has(token.toLowerCase())
? (balances.get(token.toLowerCase()) ?? null)
: await tokenBalance({
Expand Down Expand Up @@ -452,7 +450,7 @@ function currentKeyOutput(options: {
status: string | null;
}) {
if (!options.key) return null;
const limit = options.key.limits[0];
const limit = options.key.limits?.[0];
const token = limit?.token ?? tokenAddress(options.chain ?? options.key.chainId);
const spendingLimits = accessKeyLimitsOutput(options.key);
return {
Expand Down Expand Up @@ -481,7 +479,7 @@ function currentKeyOutput(options: {
}

function accessKeyLimitsOutput(key: WalletState["accessKeys"][number]) {
return key.limits.map((limit) => ({
return (key.limits ?? []).map((limit) => ({
unlimited: false,
symbol: tokenSymbol(limit.token),
token: limit.token.toLowerCase(),
Expand All @@ -496,11 +494,11 @@ function accessKeyScopesOutput(key: WalletState["accessKeys"][number]) {
return accessKeyScopes(key).map((scope) => ({
address: scope.address.toLowerCase(),
selector: scope.selector ?? null,
recipients: scope.recipients.map((recipient) => recipient.toLowerCase()),
recipients: (scope.recipients ?? []).map((recipient) => recipient.toLowerCase()),
}));
}

function accessKeyScopes(key: WalletState["accessKeys"][number]) {
function accessKeyScopes(key: WalletState["accessKeys"][number]): readonly AccessKeyScope[] {
if (key.scopes !== undefined) return key.scopes;
return parseKeyAuthorizationScopes(key.keyAuthorization);
}
Expand Down
Loading
Loading