@bnbagent/studio-cli 0.0.11 → 0.0.12-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/dist/_agentcoreName-DZDWEYD3.js +0 -0
- package/dist/_twak-4XF4H5PL.js +0 -0
- package/dist/bag.js +453 -40
- package/dist/chunk-RO726HJG.js +0 -0
- package/dist/chunk-U7IDQ3K5.js +0 -0
- package/dist/{chunk-VGSWNATS.js → chunk-XJFJU2AT.js} +77 -7
- package/dist/{deployCli-4ATY3SUP.js → deployCli-IVINTRNJ.js} +1 -1
- package/package.json +12 -13
- package/recipes/agent/recipe.toml +1 -1
- package/recipes/runtimes/agentcore/recipe.toml +1 -1
- package/recipes/runtimes/azure-foundry/recipe.toml +1 -1
- package/recipes/wallet/recipe.toml +7 -2
- package/recipes/x402-buyer/recipe.toml +1 -1
- package/skills/references/bnbagent-studio-buying-from-bazaar.md +4 -1
- package/skills/references/bnbagent-studio-extending-signing.md +1 -1
- package/skills/references/bnbagent-studio-selling-via-b402.md +2 -1
- package/skills/references/bnbagent-studio-using-altana-wallet.md +2 -0
package/dist/bag.js
CHANGED
|
@@ -52,7 +52,7 @@ import {
|
|
|
52
52
|
x402SellerIsFree,
|
|
53
53
|
x402SellerPricingState,
|
|
54
54
|
x402SellerUsesB402
|
|
55
|
-
} from "./chunk-
|
|
55
|
+
} from "./chunk-XJFJU2AT.js";
|
|
56
56
|
import {
|
|
57
57
|
TWAK_CLI_MIN_VERSION,
|
|
58
58
|
TWAK_CLI_VERSION,
|
|
@@ -230,7 +230,7 @@ import {
|
|
|
230
230
|
var CAMPAIGN_DOC_URL = "https://www.bnbchain.org/en/blog/bnb-agent-studio-is-live-on-bnb-chain-ai-agents-from-one-prompt";
|
|
231
231
|
var CAMPAIGN_CHECK_TIMEOUT_MS = 6e3;
|
|
232
232
|
async function fetchCampaignActive() {
|
|
233
|
-
const { bnbPlatformApiUrl: bnbPlatformApiUrl2 } = await import("./deployCli-
|
|
233
|
+
const { bnbPlatformApiUrl: bnbPlatformApiUrl2 } = await import("./deployCli-IVINTRNJ.js");
|
|
234
234
|
const controller = new AbortController();
|
|
235
235
|
const timer = setTimeout(() => controller.abort(), CAMPAIGN_CHECK_TIMEOUT_MS);
|
|
236
236
|
try {
|
|
@@ -2823,6 +2823,19 @@ var ERC20_BALANCE_ABI = [
|
|
|
2823
2823
|
outputs: [{ name: "", type: "uint256" }]
|
|
2824
2824
|
}
|
|
2825
2825
|
];
|
|
2826
|
+
var ERC20_ALLOWANCE_ABI = [
|
|
2827
|
+
{
|
|
2828
|
+
type: "function",
|
|
2829
|
+
name: "allowance",
|
|
2830
|
+
stateMutability: "view",
|
|
2831
|
+
inputs: [
|
|
2832
|
+
{ name: "owner", type: "address" },
|
|
2833
|
+
{ name: "spender", type: "address" }
|
|
2834
|
+
],
|
|
2835
|
+
outputs: [{ name: "", type: "uint256" }]
|
|
2836
|
+
}
|
|
2837
|
+
];
|
|
2838
|
+
var PERMIT2_ADDRESS = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
|
|
2826
2839
|
function client(networkName) {
|
|
2827
2840
|
const net2 = getNetwork(networkName);
|
|
2828
2841
|
return createPublicClient({ transport: http(net2.rpcUrl) });
|
|
@@ -2851,6 +2864,20 @@ async function readUBalanceRaw(address, networkName) {
|
|
|
2851
2864
|
});
|
|
2852
2865
|
return raw;
|
|
2853
2866
|
}
|
|
2867
|
+
async function readUAllowanceRaw(owner, spender, networkName) {
|
|
2868
|
+
const net2 = getNetwork(networkName);
|
|
2869
|
+
const uToken = net2.tokens.U;
|
|
2870
|
+
if (uToken === void 0) {
|
|
2871
|
+
return null;
|
|
2872
|
+
}
|
|
2873
|
+
const raw = await client(networkName).readContract({
|
|
2874
|
+
address: getAddress(uToken.address),
|
|
2875
|
+
abi: ERC20_ALLOWANCE_ABI,
|
|
2876
|
+
functionName: "allowance",
|
|
2877
|
+
args: [getAddress(owner), getAddress(spender)]
|
|
2878
|
+
});
|
|
2879
|
+
return raw;
|
|
2880
|
+
}
|
|
2854
2881
|
async function readTransactionSeen(txHash, networkName) {
|
|
2855
2882
|
try {
|
|
2856
2883
|
await client(networkName).getTransaction({
|
|
@@ -2937,7 +2964,7 @@ function canBuildWallet(root, data) {
|
|
|
2937
2964
|
const cfg = data ?? loadAgentToml(root);
|
|
2938
2965
|
const walletCfg = tableOf2(cfg, "wallet");
|
|
2939
2966
|
const kind = walletCfg.kind;
|
|
2940
|
-
if (kind === "twak" || kind === "altana") {
|
|
2967
|
+
if (kind === "twak" || kind === "altana" || kind === "turnkey") {
|
|
2941
2968
|
return false;
|
|
2942
2969
|
}
|
|
2943
2970
|
if (!process.env.WALLET_PASSWORD) {
|
|
@@ -2955,7 +2982,7 @@ function canBuildWallet(root, data) {
|
|
|
2955
2982
|
function walletAddressForChecks(root, data) {
|
|
2956
2983
|
const cfg = data ?? loadAgentToml(root);
|
|
2957
2984
|
const walletCfg = tableOf2(cfg, "wallet");
|
|
2958
|
-
if (walletCfg.kind === "twak" || walletCfg.kind === "altana") {
|
|
2985
|
+
if (walletCfg.kind === "twak" || walletCfg.kind === "altana" || walletCfg.kind === "turnkey") {
|
|
2959
2986
|
const addr = String(walletCfg.address ?? "").trim();
|
|
2960
2987
|
return addr || null;
|
|
2961
2988
|
}
|
|
@@ -3729,7 +3756,7 @@ function checkAltanaSdkResolvable(root, _target) {
|
|
|
3729
3756
|
level: Level.CRITICAL,
|
|
3730
3757
|
name: "altana_sdk_resolvable",
|
|
3731
3758
|
message: `@altananetwork/sdk is not resolvable from the agent project${failure ? ` (${failure})` : ""} \u2014 the deployed runtime cannot build the Altana session wallet at cold start.`,
|
|
3732
|
-
fixCmd: "pnpm add @altananetwork/sdk@0.
|
|
3759
|
+
fixCmd: "pnpm add @altananetwork/sdk@0.7.1",
|
|
3733
3760
|
details: failure ? { error: failure } : {}
|
|
3734
3761
|
}
|
|
3735
3762
|
];
|
|
@@ -4708,6 +4735,28 @@ var managedAzureFoundryChecks = [
|
|
|
4708
4735
|
checkAltanaSessionNotInsideAgent
|
|
4709
4736
|
];
|
|
4710
4737
|
|
|
4738
|
+
// src/cli/_turnkeyGuidance.ts
|
|
4739
|
+
function turnkeySetupGuidance() {
|
|
4740
|
+
return `
|
|
4741
|
+
Turnkey setup (official CLI: https://docs.turnkey.com/sdks/cli):
|
|
4742
|
+
1. In the dashboard's top-right user menu, copy the Organization ID into
|
|
4743
|
+
TURNKEY_ORG_ID.
|
|
4744
|
+
2. Generate a P-256 API key locally, then register its public key under
|
|
4745
|
+
User Details -> Create API keys:
|
|
4746
|
+
turnkey generate api-key --organization "$TURNKEY_ORG_ID" --key-name bnbagent-studio
|
|
4747
|
+
Set TURNKEY_API_PUBLIC_KEY to the generated public key and
|
|
4748
|
+
TURNKEY_API_PRIVATE_KEY to its locally generated private key. Keep the
|
|
4749
|
+
private key out of argv, logs, and source control.
|
|
4750
|
+
3. Create a wallet and an Ethereum account:
|
|
4751
|
+
turnkey wallets create --name bnbagent-studio --key-name bnbagent-studio
|
|
4752
|
+
turnkey wallets accounts create --wallet bnbagent-studio --address-format ADDRESS_FORMAT_ETHEREUM --key-name bnbagent-studio
|
|
4753
|
+
4. Set TURNKEY_SIGN_WITH to the returned 0x Ethereum account address. It is
|
|
4754
|
+
not a Turnkey wallet id (UUID).
|
|
4755
|
+
5. Store all four TURNKEY_* values in the owner-only .studio/.env.local,
|
|
4756
|
+
then run \`(cd app/agent && bag wallet new)\` to validate and anchor the
|
|
4757
|
+
address. No signing key is created or downloaded by bag.`;
|
|
4758
|
+
}
|
|
4759
|
+
|
|
4711
4760
|
// src/cli/llm.ts
|
|
4712
4761
|
import * as fs18 from "fs";
|
|
4713
4762
|
import * as path17 from "path";
|
|
@@ -6587,6 +6636,7 @@ import {
|
|
|
6587
6636
|
} from "@bnbagent/studio-runtime/config";
|
|
6588
6637
|
import { tbnbFaucetHint as tbnbFaucetHint2 } from "@bnbagent/studio-runtime/networks";
|
|
6589
6638
|
import { buildPolicy, buildWallet } from "@bnbagent/studio-runtime/wallet";
|
|
6639
|
+
import { getAddress as toChecksumAddress } from "viem";
|
|
6590
6640
|
|
|
6591
6641
|
// src/cli/walletSession.ts
|
|
6592
6642
|
import * as fs21 from "fs";
|
|
@@ -7318,6 +7368,9 @@ async function cmdNew(opts) {
|
|
|
7318
7368
|
if (kind === "twak") {
|
|
7319
7369
|
return cmdNewTwak(projectRoot, walletCfg);
|
|
7320
7370
|
}
|
|
7371
|
+
if (kind === "turnkey") {
|
|
7372
|
+
return cmdNewTurnkey(projectRoot);
|
|
7373
|
+
}
|
|
7321
7374
|
const privateKey = await resolvePrivateKeyArg(opts.privateKey);
|
|
7322
7375
|
const password = requireDurablePassword(projectRoot);
|
|
7323
7376
|
const keystoreDir = resolveKeystoreDir2(
|
|
@@ -7381,6 +7434,28 @@ Install it (Node >=22): npm install -g @trustwallet/cli@${TWAK_CLI_VERSION}`
|
|
|
7381
7434
|
printNextAfterNew(projectRoot, address);
|
|
7382
7435
|
return 0;
|
|
7383
7436
|
}
|
|
7437
|
+
function cmdNewTurnkey(projectRoot) {
|
|
7438
|
+
const signWith = String(process.env.TURNKEY_SIGN_WITH ?? "").trim();
|
|
7439
|
+
if (signWith === "") {
|
|
7440
|
+
printErr(
|
|
7441
|
+
`error: TURNKEY_SIGN_WITH is not set (wallet.kind = 'turnkey').
|
|
7442
|
+
${turnkeySetupGuidance()}`
|
|
7443
|
+
);
|
|
7444
|
+
return 1;
|
|
7445
|
+
}
|
|
7446
|
+
let address;
|
|
7447
|
+
try {
|
|
7448
|
+
address = toChecksumAddress(signWith);
|
|
7449
|
+
} catch {
|
|
7450
|
+
printErr(
|
|
7451
|
+
`error: TURNKEY_SIGN_WITH must be the wallet account's Ethereum address (0x + 40 hex chars), not a Turnkey wallet id \u2014 copy it from the dashboard wallet-account view. Got: '${signWith}'`
|
|
7452
|
+
);
|
|
7453
|
+
return 1;
|
|
7454
|
+
}
|
|
7455
|
+
printOut(address);
|
|
7456
|
+
persistAddress(projectRoot, address);
|
|
7457
|
+
return 0;
|
|
7458
|
+
}
|
|
7384
7459
|
function ensureTwakCredentials(walletFile, homeDir) {
|
|
7385
7460
|
const twakDir = path21.dirname(walletFile);
|
|
7386
7461
|
const target = path21.join(twakDir, "credentials.json");
|
|
@@ -7558,6 +7633,33 @@ function cmdShow5(projectRootArg2) {
|
|
|
7558
7633
|
);
|
|
7559
7634
|
return 0;
|
|
7560
7635
|
}
|
|
7636
|
+
if (kind === "turnkey") {
|
|
7637
|
+
const anchored = String(walletCfg.address ?? "").trim();
|
|
7638
|
+
const signWith = String(process.env.TURNKEY_SIGN_WITH ?? "").trim();
|
|
7639
|
+
const address2 = anchored || signWith;
|
|
7640
|
+
if (!address2) {
|
|
7641
|
+
throw new Error(
|
|
7642
|
+
"cannot resolve the Turnkey wallet address: no [wallet].address is anchored in studio.toml and TURNKEY_SIGN_WITH is not set \u2014 fill .studio/.env.local, then run `bag wallet new`."
|
|
7643
|
+
);
|
|
7644
|
+
}
|
|
7645
|
+
const requiredEnv = [
|
|
7646
|
+
"TURNKEY_API_PUBLIC_KEY",
|
|
7647
|
+
"TURNKEY_API_PRIVATE_KEY",
|
|
7648
|
+
"TURNKEY_ORG_ID",
|
|
7649
|
+
"TURNKEY_SIGN_WITH"
|
|
7650
|
+
];
|
|
7651
|
+
const present = requiredEnv.filter((key) => process.env[key]).length;
|
|
7652
|
+
const baseUrl = process.env.TURNKEY_API_BASE_URL || "https://api.turnkey.com";
|
|
7653
|
+
printOut(`address: ${address2}`);
|
|
7654
|
+
printOut("source: turnkey");
|
|
7655
|
+
printOut(
|
|
7656
|
+
`key_location: remote:turnkey (${baseUrl}; key held in AWS Nitro enclave, never leaves)`
|
|
7657
|
+
);
|
|
7658
|
+
printOut(
|
|
7659
|
+
`credentials: ${present}/${requiredEnv.length} TURNKEY_* env vars set`
|
|
7660
|
+
);
|
|
7661
|
+
return 0;
|
|
7662
|
+
}
|
|
7561
7663
|
const password = requirePassword2();
|
|
7562
7664
|
const keystoreDir = resolveKeystoreDir2(projectRoot, null, walletCfg);
|
|
7563
7665
|
const provider = new EVMWalletProvider({
|
|
@@ -7650,7 +7752,14 @@ async function cmdSign(msg, projectRootArg2) {
|
|
|
7650
7752
|
);
|
|
7651
7753
|
}
|
|
7652
7754
|
let provider;
|
|
7653
|
-
if (kind === "
|
|
7755
|
+
if (kind === "turnkey") {
|
|
7756
|
+
printErr(
|
|
7757
|
+
"note: Turnkey signatures are billed (free tier 25/month at 1 req/s; pay-as-you-go $0.10 each)."
|
|
7758
|
+
);
|
|
7759
|
+
provider = buildWallet(walletCfg, projectRoot, {
|
|
7760
|
+
network: projectNetwork(projectRoot)
|
|
7761
|
+
});
|
|
7762
|
+
} else if (kind === "twak") {
|
|
7654
7763
|
provider = twakProvider(projectRoot, walletCfg);
|
|
7655
7764
|
} else {
|
|
7656
7765
|
const password = requirePassword2();
|
|
@@ -7675,10 +7784,10 @@ async function cmdBalance(opts) {
|
|
|
7675
7784
|
const walletCfg = data.wallet !== null && typeof data.wallet === "object" ? data.wallet : {};
|
|
7676
7785
|
let address;
|
|
7677
7786
|
const kind = walletKind(walletCfg);
|
|
7678
|
-
if (kind === "twak" || kind === "altana") {
|
|
7787
|
+
if (kind === "twak" || kind === "altana" || kind === "turnkey") {
|
|
7679
7788
|
address = String(walletCfg.address ?? "").trim();
|
|
7680
7789
|
if (!address) {
|
|
7681
|
-
const nextStep = kind === "twak" ? "(adopts the twak wallet's address) first." : "to create the Altana admin keystore first.";
|
|
7790
|
+
const nextStep = kind === "twak" ? "(adopts the twak wallet's address) first." : kind === "turnkey" ? "(set TURNKEY_SIGN_WITH in .studio/.env.local first \u2014 `bag wallet new` adopts it)." : "to create the Altana admin keystore first.";
|
|
7682
7791
|
throw new Error(
|
|
7683
7792
|
`no [wallet].address anchored in studio.toml \u2014 run bag wallet new ${nextStep}`
|
|
7684
7793
|
);
|
|
@@ -8068,8 +8177,8 @@ function registerInit(program) {
|
|
|
8068
8177
|
).addOption(
|
|
8069
8178
|
new Option2(
|
|
8070
8179
|
"--wallet-kind <kind>",
|
|
8071
|
-
"Wallet backend for the Agent (default: evm-local = encrypted local keystore at the workspace root .studio/wallets/; CodeZip deploy). altana \u2014 encrypted local admin keystore plus a bounded runtime session; deploys ship ONLY the session (ALTANA_SESSION secret). twak \u2014 FULLY SUPPORTED, opt in: Trust Wallet Agent Kit CLI, self-custody encrypted mnemonic in a PROJECT-DEDICATED home (.studio/twak); deploys as a container image."
|
|
8072
|
-
).choices(["twak", "evm-local", "altana"])
|
|
8180
|
+
"Wallet backend for the Agent (default: evm-local = encrypted local keystore at the workspace root .studio/wallets/; CodeZip deploy). altana \u2014 encrypted local admin keystore plus a bounded runtime session; deploys ship ONLY the session (ALTANA_SESSION secret). twak \u2014 FULLY SUPPORTED, opt in: Trust Wallet Agent Kit CLI, self-custody encrypted mnemonic in a PROJECT-DEDICATED home (.studio/twak); deploys as a container image. turnkey \u2014 remote signer: the key lives in Turnkey's AWS Nitro enclave and the Agent signs via TURNKEY_* API credentials; CodeZip deploy; every successful signature is billed."
|
|
8181
|
+
).choices(["twak", "evm-local", "altana", "turnkey"])
|
|
8073
8182
|
).option(
|
|
8074
8183
|
"--twak-home <path>",
|
|
8075
8184
|
"twak only: point this project at an EXISTING twak wallet home (the HOME-STYLE PARENT dir that contains .twak/wallet.json \u2014 NOT the .twak dir itself; a .twak path holding a wallet is auto-corrected to its parent) instead of the dedicated .studio/twak. Written to [wallet].twak_home."
|
|
@@ -8382,9 +8491,9 @@ async function cmdInitFlow(nameArg, opts) {
|
|
|
8382
8491
|
}
|
|
8383
8492
|
const budgetFlag = opts.enableAutoTopup ? "enable" : opts.autoTopup === false ? "disable" : null;
|
|
8384
8493
|
const budgetChoice = walletKind2 === "altana" && llmProvider !== "pieverse-llm" && budgetFlag === null ? null : await resolveBudgetChoice(budgetFlag);
|
|
8385
|
-
if ((rails === "b402" || rails === "both") && x402SellerPricingState({ price_usd: b402Price }).kind === "paid" && !["evm-local", "twak"].includes(walletKind2)) {
|
|
8494
|
+
if ((rails === "b402" || rails === "both") && x402SellerPricingState({ price_usd: b402Price }).kind === "paid" && !["evm-local", "twak", "turnkey"].includes(walletKind2)) {
|
|
8386
8495
|
printErr(
|
|
8387
|
-
`error: the b402 seller rail supports wallet.kind evm-local or
|
|
8496
|
+
`error: the b402 seller rail supports wallet.kind evm-local, twak or turnkey only; '${walletKind2}' cannot act as the b402 payout wallet. Re-run with --rails 8183 or a supported --wallet-kind.`
|
|
8388
8497
|
);
|
|
8389
8498
|
fs23.rmSync(target, { recursive: true, force: true });
|
|
8390
8499
|
return 2;
|
|
@@ -8481,6 +8590,8 @@ async function cmdInitFlow(nameArg, opts) {
|
|
|
8481
8590
|
}
|
|
8482
8591
|
} else if (walletKind2 === "altana") {
|
|
8483
8592
|
printAltanaNotice();
|
|
8593
|
+
} else if (walletKind2 === "turnkey") {
|
|
8594
|
+
printTurnkeyNotice();
|
|
8484
8595
|
} else {
|
|
8485
8596
|
printEvmLocalNotice(
|
|
8486
8597
|
derivePackaging(walletKind2, destination, platformArtifact2, runtime)
|
|
@@ -8717,6 +8828,9 @@ function computeAgentNodeDeps(runtime, provider, protocols = "A2A", walletKind2
|
|
|
8717
8828
|
if (walletKind2 === "altana") {
|
|
8718
8829
|
raw.push(...readRecipeNodeDeps("wallet", "altana"));
|
|
8719
8830
|
}
|
|
8831
|
+
if (walletKind2 === "turnkey") {
|
|
8832
|
+
raw.push(...readRecipeNodeDeps("wallet", "turnkey"));
|
|
8833
|
+
}
|
|
8720
8834
|
const out = {};
|
|
8721
8835
|
const core = splitDep(coreRequirement());
|
|
8722
8836
|
for (const dep of raw) {
|
|
@@ -8890,6 +9004,18 @@ kind = "altana"
|
|
|
8890
9004
|
keystore_dir = "../../.studio/wallets"
|
|
8891
9005
|
session_file = "../../.studio/wallets/altana-session.json"
|
|
8892
9006
|
# address = "0x..." # filled by \`bag wallet new\`; session must match it`;
|
|
9007
|
+
}
|
|
9008
|
+
if (walletKind2 === "turnkey") {
|
|
9009
|
+
return `[wallet]
|
|
9010
|
+
# Turnkey remote signer. The key is generated and held in Turnkey's AWS Nitro
|
|
9011
|
+
# enclave \u2014 no key material ever exists in this project or its deploys. The
|
|
9012
|
+
# Agent signs via the Turnkey API using the TURNKEY_* credentials in
|
|
9013
|
+
# .studio/.env.local. Billing: every successful signature is billed (free
|
|
9014
|
+
# tier: 25 signatures/month at 1 request/second; pay-as-you-go $0.10 each).
|
|
9015
|
+
# PRODUCTION: use a NON-ROOT API user restricted by an explicit ALLOW
|
|
9016
|
+
# policy \u2014 a root user's API key bypasses ALL Turnkey server-side policies.
|
|
9017
|
+
kind = "turnkey"
|
|
9018
|
+
# address = "0x..." # filled by \`bag wallet new\` (adopts TURNKEY_SIGN_WITH)`;
|
|
8893
9019
|
}
|
|
8894
9020
|
return `[wallet]
|
|
8895
9021
|
# Local keystore signer. The Agent is the SOLE key-holder/signer.
|
|
@@ -9088,6 +9214,23 @@ function renderAgentEnvLocal(provider, storageProvider, walletKind2, rails, b402
|
|
|
9088
9214
|
"# TWAK_ACCESS_ID=",
|
|
9089
9215
|
"# TWAK_HMAC_SECRET="
|
|
9090
9216
|
);
|
|
9217
|
+
} else if (walletKind2 === "turnkey") {
|
|
9218
|
+
lines.push(
|
|
9219
|
+
"",
|
|
9220
|
+
"# Turnkey API credentials (dashboard \u2192 API keys). The P-256 API key",
|
|
9221
|
+
"# pair authenticates this Agent to the enclave; the wallet's signing",
|
|
9222
|
+
"# key never leaves Turnkey. Use a NON-ROOT API user + explicit ALLOW",
|
|
9223
|
+
"# policy in production (root keys bypass all Turnkey policies).",
|
|
9224
|
+
"TURNKEY_API_PUBLIC_KEY=",
|
|
9225
|
+
"TURNKEY_API_PRIVATE_KEY=",
|
|
9226
|
+
"# Organization id (dashboard \u2192 settings):",
|
|
9227
|
+
"TURNKEY_ORG_ID=",
|
|
9228
|
+
"# Account to sign with \u2014 MUST be the 0x Ethereum ADDRESS itself, not",
|
|
9229
|
+
"# a Turnkey wallet id. `bag wallet new` anchors it into studio.toml.",
|
|
9230
|
+
"TURNKEY_SIGN_WITH=",
|
|
9231
|
+
"# Optional API host override (default https://api.turnkey.com):",
|
|
9232
|
+
"# TURNKEY_API_BASE_URL="
|
|
9233
|
+
);
|
|
9091
9234
|
} else if (walletKind2 === "evm-local" || walletKind2 === "altana") {
|
|
9092
9235
|
lines.push(
|
|
9093
9236
|
"",
|
|
@@ -9202,7 +9345,7 @@ entrypoint code in \`src/signing.ts\` \u2014 never an LLM-callable tool.
|
|
|
9202
9345
|
${mode === "both" ? filesBoth : mode === "mcp" ? filesMcp : filesA2a}
|
|
9203
9346
|
${shared}
|
|
9204
9347
|
- \`.env.local\` \u2014 Agent secrets; on deploy they are sent to the **operator's**
|
|
9205
|
-
Secrets Manager (the scoped, consented commitment-#2 exception). ${walletKind2 === "altana" ? "Only the\n bounded session ships (as `ALTANA_SESSION`); tighten it with\n `bag wallet session grant --force` \u2014 do not create a new wallet." : "Use a\n THROWAWAY testnet wallet \u2014 `(cd app/agent && bag wallet new)`."}
|
|
9348
|
+
Secrets Manager (the scoped, consented commitment-#2 exception). ${walletKind2 === "altana" ? "Only the\n bounded session ships (as `ALTANA_SESSION`); tighten it with\n `bag wallet session grant --force` \u2014 do not create a new wallet." : walletKind2 === "turnkey" ? "No key\n material exists locally \u2014 only the TURNKEY_* API credentials ship; the\n signing key stays in Turnkey's enclave. Fund the TURNKEY_SIGN_WITH\n address with a little tBNB; every successful signature is billed." : "Use a\n THROWAWAY testnet wallet \u2014 `(cd app/agent && bag wallet new)`."}
|
|
9206
9349
|
|
|
9207
9350
|
## Run locally
|
|
9208
9351
|
|
|
@@ -9311,12 +9454,12 @@ function ensureCursorGitignore(gitignore) {
|
|
|
9311
9454
|
${addition}`);
|
|
9312
9455
|
}
|
|
9313
9456
|
async function resolveWalletKind(flagValue, isTty) {
|
|
9314
|
-
if (flagValue === "evm-local" || flagValue === "twak" || flagValue === "altana") {
|
|
9457
|
+
if (flagValue === "evm-local" || flagValue === "twak" || flagValue === "altana" || flagValue === "turnkey") {
|
|
9315
9458
|
return flagValue;
|
|
9316
9459
|
}
|
|
9317
9460
|
if (!isTty) {
|
|
9318
9461
|
printErr(
|
|
9319
|
-
"info: wallet backend defaulting to 'evm-local' (non-interactive). To choose explicitly, re-run with --wallet-kind evm-local or --wallet-kind twak or --wallet-kind
|
|
9462
|
+
"info: wallet backend defaulting to 'evm-local' (non-interactive). To choose explicitly, re-run with --wallet-kind evm-local or --wallet-kind twak, --wallet-kind altana or --wallet-kind turnkey."
|
|
9320
9463
|
);
|
|
9321
9464
|
return "evm-local";
|
|
9322
9465
|
}
|
|
@@ -9330,9 +9473,13 @@ async function resolveWalletKind(flagValue, isTty) {
|
|
|
9330
9473
|
printOut(
|
|
9331
9474
|
" 3. altana \u2014 bounded session signer; incompatible with pieverse-llm and paid b402 selling"
|
|
9332
9475
|
);
|
|
9333
|
-
|
|
9476
|
+
printOut(
|
|
9477
|
+
" 4. turnkey \u2014 remote signer; key held in Turnkey's AWS Nitro enclave; billable signatures"
|
|
9478
|
+
);
|
|
9479
|
+
const answer = (await promptUser("Wallet backend [1-4, Enter = evm-local]: ")).trim().toLowerCase();
|
|
9334
9480
|
if (answer === "2" || answer === "twak") return "twak";
|
|
9335
9481
|
if (answer === "3" || answer === "altana") return "altana";
|
|
9482
|
+
if (answer === "4" || answer === "turnkey") return "turnkey";
|
|
9336
9483
|
if (answer !== "" && answer !== "1" && answer !== "evm-local") {
|
|
9337
9484
|
printErr(`hint: unknown wallet backend '${answer}' \u2014 using evm-local.`);
|
|
9338
9485
|
}
|
|
@@ -9614,6 +9761,12 @@ async function runOnboarding(o) {
|
|
|
9614
9761
|
if (o.walletKind === "twak") {
|
|
9615
9762
|
return runOnboardingTwak(o);
|
|
9616
9763
|
}
|
|
9764
|
+
if (o.walletKind === "turnkey") {
|
|
9765
|
+
printOut(
|
|
9766
|
+
"turnkey onboarding: no local key is created. Fill the TURNKEY_* credentials in .studio/.env.local (Turnkey dashboard \u2192 API keys / settings / wallet account), then run `(cd app/agent && bag wallet new)` to adopt + anchor the signing address."
|
|
9767
|
+
);
|
|
9768
|
+
return false;
|
|
9769
|
+
}
|
|
9617
9770
|
const password = await promptPassword();
|
|
9618
9771
|
if (password === null) {
|
|
9619
9772
|
return false;
|
|
@@ -9983,7 +10136,33 @@ NOTE \u2014 wallet.kind = "altana" (bounded runtime session):
|
|
|
9983
10136
|
\`bag wallet session grant --force\` and redeploy.`
|
|
9984
10137
|
);
|
|
9985
10138
|
}
|
|
10139
|
+
function printTurnkeyNotice() {
|
|
10140
|
+
printOut(
|
|
10141
|
+
`
|
|
10142
|
+
NOTE \u2014 wallet.kind = "turnkey" (remote signer, keys in Turnkey's AWS Nitro enclave):
|
|
10143
|
+
\xB7 WALLET: no key material exists locally \u2014 the Agent signs via the TURNKEY_*
|
|
10144
|
+
API credentials in .studio/.env.local.
|
|
10145
|
+
${turnkeySetupGuidance()}
|
|
10146
|
+
\xB7 BILLING: every successful signature is billed (free tier: 25/month at
|
|
10147
|
+
1 request/second; pay-as-you-go $0.10 each) \u2014 budget accordingly.
|
|
10148
|
+
\xB7 PRODUCTION: use a NON-ROOT API user restricted by an explicit ALLOW policy;
|
|
10149
|
+
a root user's API key bypasses ALL Turnkey server-side policies.`
|
|
10150
|
+
);
|
|
10151
|
+
}
|
|
9986
10152
|
function printPlatformWalletSuggestion(walletKind2) {
|
|
10153
|
+
if (walletKind2 === "turnkey") {
|
|
10154
|
+
printOut(
|
|
10155
|
+
`
|
|
10156
|
+
NOTE \u2014 destination = "platform" (48h TESTNET TRIAL on the BNB Chain managed platform):
|
|
10157
|
+
\xB7 This is a sandbox, not a production seller \u2014 the runtime is auto-reclaimed at 48h.
|
|
10158
|
+
\xB7 To sign, ONLY the TURNKEY_* API credentials are transmitted to the operator's
|
|
10159
|
+
Secrets Manager on deploy \u2014 the signing key never leaves Turnkey's enclave.
|
|
10160
|
+
\xB7 Want a smaller blast radius? Use a NON-ROOT API user whose ALLOW policy
|
|
10161
|
+
covers only this Agent's operations, and revoke it from the Turnkey
|
|
10162
|
+
dashboard when the trial ends.`
|
|
10163
|
+
);
|
|
10164
|
+
return;
|
|
10165
|
+
}
|
|
9987
10166
|
if (walletKind2 === "altana") {
|
|
9988
10167
|
printOut(
|
|
9989
10168
|
`
|
|
@@ -10214,6 +10393,17 @@ function printNextSteps(name, provider, o = {}) {
|
|
|
10214
10393
|
printOut(
|
|
10215
10394
|
" (cd app/agent && bag wallet session status) # local, secret-free summary"
|
|
10216
10395
|
);
|
|
10396
|
+
} else if (walletKind2 === "turnkey") {
|
|
10397
|
+
printOut(
|
|
10398
|
+
" # 1. edit .studio/.env.local and set the TURNKEY_* credentials (Turnkey dashboard \u2192 API keys / settings / wallet account)"
|
|
10399
|
+
);
|
|
10400
|
+
printOut(
|
|
10401
|
+
" # use a NON-ROOT API user + explicit ALLOW policy; TURNKEY_SIGN_WITH is the 0x ADDRESS, not a wallet id"
|
|
10402
|
+
);
|
|
10403
|
+
printOut(
|
|
10404
|
+
" # 2. adopt + anchor the Turnkey address (no local key is created):"
|
|
10405
|
+
);
|
|
10406
|
+
printOut(" (cd app/agent && bag wallet new)");
|
|
10217
10407
|
} else {
|
|
10218
10408
|
printOut(
|
|
10219
10409
|
" # 1. edit .studio/.env.local and set WALLET_PASSWORD (encrypts the keystore + signs all on-chain ops)"
|
|
@@ -10437,6 +10627,10 @@ function printConfigSummary(agentRoot2) {
|
|
|
10437
10627
|
".studio/wallets/altana-session.json"
|
|
10438
10628
|
)}`
|
|
10439
10629
|
);
|
|
10630
|
+
} else if (walletKind2 === "turnkey") {
|
|
10631
|
+
printOut(
|
|
10632
|
+
" wallet : Turnkey remote signer (key in AWS Nitro enclave; TURNKEY_* credentials in .studio/.env.local) \u2014 the sole signer; receives your $U"
|
|
10633
|
+
);
|
|
10440
10634
|
} else {
|
|
10441
10635
|
printOut(
|
|
10442
10636
|
` wallet : local keystore (${shown(
|
|
@@ -10557,6 +10751,16 @@ function runtimeEnvKeysCore(cfg, resolvable) {
|
|
|
10557
10751
|
}
|
|
10558
10752
|
} else if (walletKind2 === "altana") {
|
|
10559
10753
|
keys = [];
|
|
10754
|
+
} else if (walletKind2 === "turnkey") {
|
|
10755
|
+
keys = [
|
|
10756
|
+
"TURNKEY_API_PUBLIC_KEY",
|
|
10757
|
+
"TURNKEY_API_PRIVATE_KEY",
|
|
10758
|
+
"TURNKEY_ORG_ID",
|
|
10759
|
+
"TURNKEY_SIGN_WITH"
|
|
10760
|
+
];
|
|
10761
|
+
if (resolvable("TURNKEY_API_BASE_URL")) {
|
|
10762
|
+
keys.push("TURNKEY_API_BASE_URL");
|
|
10763
|
+
}
|
|
10560
10764
|
} else {
|
|
10561
10765
|
keys = ["WALLET_PASSWORD"];
|
|
10562
10766
|
}
|
|
@@ -11081,10 +11285,17 @@ async function cmdDev(opts) {
|
|
|
11081
11285
|
);
|
|
11082
11286
|
return 2;
|
|
11083
11287
|
}
|
|
11084
|
-
const
|
|
11085
|
-
|
|
11288
|
+
const requiredWalletEnv = walletKind2 === "twak" ? ["TWAK_WALLET_PASSWORD"] : walletKind2 === "altana" ? [] : walletKind2 === "turnkey" ? [
|
|
11289
|
+
"TURNKEY_API_PUBLIC_KEY",
|
|
11290
|
+
"TURNKEY_API_PRIVATE_KEY",
|
|
11291
|
+
"TURNKEY_ORG_ID",
|
|
11292
|
+
"TURNKEY_SIGN_WITH"
|
|
11293
|
+
] : ["WALLET_PASSWORD"];
|
|
11294
|
+
const missingWalletEnv = requiredWalletEnv.filter((key) => !process.env[key]);
|
|
11295
|
+
if (missingWalletEnv.length > 0) {
|
|
11296
|
+
const plural = missingWalletEnv.length > 1 ? "vars are" : "var is";
|
|
11086
11297
|
printErr(
|
|
11087
|
-
`error: ${
|
|
11298
|
+
`error: ${missingWalletEnv.join(", ")} env ${plural} required to run \`bag dev\` with wallet.kind='${walletKind2}' (the Agent is the sole signer). Set ${missingWalletEnv.length > 1 ? "them" : "it"} in .studio/.env.local or your shell.`
|
|
11088
11299
|
);
|
|
11089
11300
|
return 2;
|
|
11090
11301
|
}
|
|
@@ -11465,6 +11676,9 @@ async function checkLocalKeystoreExists(root, _target) {
|
|
|
11465
11676
|
if (walletCfg.kind === "altana") {
|
|
11466
11677
|
return [];
|
|
11467
11678
|
}
|
|
11679
|
+
if (walletCfg.kind === "turnkey") {
|
|
11680
|
+
return [];
|
|
11681
|
+
}
|
|
11468
11682
|
const signer = walletCfg.signer ?? "local";
|
|
11469
11683
|
if (signer !== "local") {
|
|
11470
11684
|
return [];
|
|
@@ -11490,6 +11704,9 @@ async function checkWalletPasswordEnvSet(root, _target) {
|
|
|
11490
11704
|
if (kind === "altana") {
|
|
11491
11705
|
return [];
|
|
11492
11706
|
}
|
|
11707
|
+
if (kind === "turnkey") {
|
|
11708
|
+
return [];
|
|
11709
|
+
}
|
|
11493
11710
|
if (process.env.WALLET_PASSWORD) {
|
|
11494
11711
|
return [];
|
|
11495
11712
|
}
|
|
@@ -12113,6 +12330,46 @@ function awsJson(stdout) {
|
|
|
12113
12330
|
return null;
|
|
12114
12331
|
}
|
|
12115
12332
|
}
|
|
12333
|
+
async function checkAwsAccountMatchesTarget(root, target) {
|
|
12334
|
+
if (target !== "agentcore") {
|
|
12335
|
+
return [];
|
|
12336
|
+
}
|
|
12337
|
+
const [targetAccount, region] = readAwsTarget(root);
|
|
12338
|
+
if (!targetAccount || !region || !await whichBin("aws")) {
|
|
12339
|
+
return [];
|
|
12340
|
+
}
|
|
12341
|
+
const identity = await runCapture("aws", [
|
|
12342
|
+
"sts",
|
|
12343
|
+
"get-caller-identity",
|
|
12344
|
+
"--region",
|
|
12345
|
+
region,
|
|
12346
|
+
"--output",
|
|
12347
|
+
"json"
|
|
12348
|
+
]);
|
|
12349
|
+
if (identity.code !== 0) {
|
|
12350
|
+
return [];
|
|
12351
|
+
}
|
|
12352
|
+
const rawAccount = awsJson(identity.stdout)?.Account;
|
|
12353
|
+
const credentialAccount = typeof rawAccount === "string" && /^\d{12}$/.test(rawAccount.trim()) ? rawAccount.trim() : null;
|
|
12354
|
+
if (credentialAccount === null || credentialAccount === targetAccount) {
|
|
12355
|
+
return [];
|
|
12356
|
+
}
|
|
12357
|
+
const targetPath = path24.join(root, "agentcore", "aws-targets.json");
|
|
12358
|
+
return [
|
|
12359
|
+
{
|
|
12360
|
+
level: Level.CRITICAL,
|
|
12361
|
+
name: "aws_account_mismatch",
|
|
12362
|
+
message: `active AWS credentials resolve to account ${credentialAccount}, but agentcore/aws-targets.json pins account ${targetAccount}. The delegated deploy rejects this mismatch before provisioning. Switch credentials, or update the local target file after confirming which account should own the deployment.`,
|
|
12363
|
+
details: {
|
|
12364
|
+
credential_account: credentialAccount,
|
|
12365
|
+
target_account: targetAccount,
|
|
12366
|
+
region,
|
|
12367
|
+
path: targetPath
|
|
12368
|
+
},
|
|
12369
|
+
fixCmd: `# edit agentcore/aws-targets.json and set the default account to ${credentialAccount}, or switch the active AWS credentials`
|
|
12370
|
+
}
|
|
12371
|
+
];
|
|
12372
|
+
}
|
|
12116
12373
|
async function checkAgentcoreQuotaHeadroom(root, target) {
|
|
12117
12374
|
if (target !== "agentcore") {
|
|
12118
12375
|
return [];
|
|
@@ -12218,6 +12475,7 @@ var allChecks = [
|
|
|
12218
12475
|
checkDeployCliRunnable,
|
|
12219
12476
|
checkRuntimeSecretsInjected,
|
|
12220
12477
|
checkAwsTargetsPopulated,
|
|
12478
|
+
checkAwsAccountMatchesTarget,
|
|
12221
12479
|
checkAgentcoreQuotaHeadroom
|
|
12222
12480
|
];
|
|
12223
12481
|
|
|
@@ -12353,7 +12611,7 @@ function collectRuntimeSecretsDetailed(root) {
|
|
|
12353
12611
|
sources[KEYSTORE_JSON_ENV] = "wallet-file";
|
|
12354
12612
|
}
|
|
12355
12613
|
}
|
|
12356
|
-
if (walletKind2 !== "altana" && !(KEYSTORE_JSON_ENV in payload) && !(TWAK_WALLET_JSON_ENV in payload)) {
|
|
12614
|
+
if (walletKind2 !== "altana" && walletKind2 !== "turnkey" && !(KEYSTORE_JSON_ENV in payload) && !(TWAK_WALLET_JSON_ENV in payload)) {
|
|
12357
12615
|
printErr(
|
|
12358
12616
|
`WARNING: no wallet signing material found (${KEYSTORE_JSON_ENV} for evm-local / ${TWAK_WALLET_JSON_ENV} for twak). The deployed runtime won't be able to sign quotes or deliveries. Create/adopt a wallet first (e.g. \`bag wallet new\`) and redeploy.`
|
|
12359
12617
|
);
|
|
@@ -15029,6 +15287,15 @@ function printAgentClientPrompt(root, invokeUrl, status) {
|
|
|
15029
15287
|
);
|
|
15030
15288
|
}
|
|
15031
15289
|
const endpointBlock = endpoints.join("\n");
|
|
15290
|
+
const commerceShapeLines = hasA2aFace(faces) ? [
|
|
15291
|
+
"MESSAGE SHAPES (complete A2A JSON-RPC requests)",
|
|
15292
|
+
'- negotiate: {"jsonrpc":"2.0","id":"request-1","method":"message/send","params":{"message":{"messageId":"message-1","role":"user","parts":[{"kind":"data","data":{"skill":"negotiate","task_description":"<what you want done>","terms":{"deliverables":"...","quality_standards":"..."}}}]}}}',
|
|
15293
|
+
'- notify_funded: {"jsonrpc":"2.0","id":"request-2","method":"message/send","params":{"message":{"messageId":"message-2","role":"user","parts":[{"kind":"data","data":{"skill":"notify_funded","job_id":123}}]}}}'
|
|
15294
|
+
] : [
|
|
15295
|
+
"MCP TOOL ARGUMENTS",
|
|
15296
|
+
'- negotiate: {"task_description":"<what you want done>","terms":{"deliverables":"...","quality_standards":"..."}}',
|
|
15297
|
+
'- notify_funded: {"job_id":123}'
|
|
15298
|
+
];
|
|
15032
15299
|
const lines = [
|
|
15033
15300
|
"",
|
|
15034
15301
|
CLIENT_PROMPT_RULE,
|
|
@@ -15061,9 +15328,7 @@ function printAgentClientPrompt(root, invokeUrl, status) {
|
|
|
15061
15328
|
"- Remote ERC-8183 callers need an OAuth2 access token:",
|
|
15062
15329
|
tokenSteps,
|
|
15063
15330
|
"",
|
|
15064
|
-
|
|
15065
|
-
'- negotiate: {"skill":"negotiate","task_description":"<what you want done>","terms":{"deliverables":"...","quality_standards":"..."}}',
|
|
15066
|
-
'- notify_funded: {"skill":"notify_funded","job_id":<int>}'
|
|
15331
|
+
...commerceShapeLines
|
|
15067
15332
|
] : [
|
|
15068
15333
|
"- The anonymous x402 route does not use the OAuth2 token flow shown for ERC-8183."
|
|
15069
15334
|
],
|
|
@@ -16510,6 +16775,28 @@ async function printAgentClientPrompt2(root, destination, opts = {}) {
|
|
|
16510
16775
|
The invoke URL carries a querystring (?qualifier=...): never
|
|
16511
16776
|
string-concatenate extra path segments onto it \u2014 that produces
|
|
16512
16777
|
an invalid URL and an HTTP 405.`;
|
|
16778
|
+
const commerceShapeLines = hasA2aFace(faces) ? [
|
|
16779
|
+
"MESSAGE SHAPES (complete A2A JSON-RPC requests)",
|
|
16780
|
+
'- negotiate: {"jsonrpc":"2.0","id":"request-1","method":"message/send","params":{"message":{"messageId":"message-1","role":"user","parts":[{"kind":"data","data":{"skill":"negotiate","task_description":"<what you want done>","terms":{"deliverables":"...","quality_standards":"..."}}}]}}}',
|
|
16781
|
+
'- notify_funded: {"jsonrpc":"2.0","id":"request-2","method":"message/send","params":{"message":{"messageId":"message-2","role":"user","parts":[{"kind":"data","data":{"skill":"notify_funded","job_id":123}}]}}}'
|
|
16782
|
+
] : [
|
|
16783
|
+
"MCP TOOL ARGUMENTS",
|
|
16784
|
+
'- negotiate: {"task_description":"<what you want done>","terms":{"deliverables":"...","quality_standards":"..."}}',
|
|
16785
|
+
'- notify_funded: {"job_id":123}'
|
|
16786
|
+
];
|
|
16787
|
+
const mcpSessionLines = hasA2aFace(faces) && hasMcpFace(faces) ? [
|
|
16788
|
+
"",
|
|
16789
|
+
"MCP SESSION FLOW (A2A+MCP through envelope-v1)",
|
|
16790
|
+
" 1) Keep X-Amzn-Bedrock-AgentCore-Runtime-Session-Id on every outer InvokeAgentRuntime request; this is the outer AgentCore runtime session.",
|
|
16791
|
+
" 2) Send an envelope-v1 POST /mcp whose decoded body is the MCP initialize request, with no inner mcp-session-id header.",
|
|
16792
|
+
' 3) Decode the envelope response and read headers["mcp-session-id"]; this is the inner MCP session, separate from the outer header.',
|
|
16793
|
+
" 4) Send notifications/initialized, then tools/list or tools/call in new envelopes whose inner headers carry that same mcp-session-id."
|
|
16794
|
+
] : hasMcpFace(faces) ? [
|
|
16795
|
+
"",
|
|
16796
|
+
"MCP SESSION FLOW",
|
|
16797
|
+
" 1) Send initialize without mcp-session-id and capture the response mcp-session-id header.",
|
|
16798
|
+
" 2) Send notifications/initialized, then tools/list or tools/call with that header."
|
|
16799
|
+
] : [];
|
|
16513
16800
|
const lines = [
|
|
16514
16801
|
"",
|
|
16515
16802
|
CLIENT_PROMPT_RULE2,
|
|
@@ -16539,9 +16826,8 @@ async function printAgentClientPrompt2(root, destination, opts = {}) {
|
|
|
16539
16826
|
"- Remote ERC-8183 callers need an OAuth2 access token:",
|
|
16540
16827
|
tokenSteps,
|
|
16541
16828
|
"",
|
|
16542
|
-
|
|
16543
|
-
|
|
16544
|
-
'- notify_funded: {"skill":"notify_funded","job_id":<int>}'
|
|
16829
|
+
...commerceShapeLines,
|
|
16830
|
+
...mcpSessionLines
|
|
16545
16831
|
] : [
|
|
16546
16832
|
"- The anonymous x402 route does not use the OAuth2 token flow shown for ERC-8183."
|
|
16547
16833
|
],
|
|
@@ -17438,7 +17724,8 @@ var SECRET_ENV_KEYS = [
|
|
|
17438
17724
|
"PIEVERSE_LLM_API_KEY",
|
|
17439
17725
|
"STORAGE_API_KEY",
|
|
17440
17726
|
"TWAK_ACCESS_ID",
|
|
17441
|
-
"TWAK_HMAC_SECRET"
|
|
17727
|
+
"TWAK_HMAC_SECRET",
|
|
17728
|
+
"TURNKEY_API_PRIVATE_KEY"
|
|
17442
17729
|
];
|
|
17443
17730
|
function tableOf14(cfg, key) {
|
|
17444
17731
|
const v = cfg[key];
|
|
@@ -17685,6 +17972,9 @@ async function checkWallet(projectRoot, data) {
|
|
|
17685
17972
|
if (walletCfg.kind === "altana") {
|
|
17686
17973
|
return checkWalletAltana(walletCfg, projectRoot, data);
|
|
17687
17974
|
}
|
|
17975
|
+
if (walletCfg.kind === "turnkey") {
|
|
17976
|
+
return checkWalletTurnkey(walletCfg);
|
|
17977
|
+
}
|
|
17688
17978
|
if (!isLocalEvmWallet(walletCfg)) {
|
|
17689
17979
|
return [
|
|
17690
17980
|
{
|
|
@@ -17738,7 +18028,59 @@ async function checkWallet(projectRoot, data) {
|
|
|
17738
18028
|
}
|
|
17739
18029
|
return out;
|
|
17740
18030
|
}
|
|
17741
|
-
|
|
18031
|
+
var TURNKEY_ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;
|
|
18032
|
+
var TURNKEY_REQUIRED_ENV = [
|
|
18033
|
+
"TURNKEY_API_PUBLIC_KEY",
|
|
18034
|
+
"TURNKEY_API_PRIVATE_KEY",
|
|
18035
|
+
"TURNKEY_ORG_ID",
|
|
18036
|
+
"TURNKEY_SIGN_WITH"
|
|
18037
|
+
];
|
|
18038
|
+
function checkWalletTurnkey(walletCfg) {
|
|
18039
|
+
const out = [];
|
|
18040
|
+
const missing = TURNKEY_REQUIRED_ENV.filter((key) => !process.env[key]);
|
|
18041
|
+
out.push(
|
|
18042
|
+
missing.length === 0 ? {
|
|
18043
|
+
name: "[wallet] turnkey credentials",
|
|
18044
|
+
status: PASS,
|
|
18045
|
+
detail: "API key pair + org id + sign-with address set; reminder: production should use a non-root API user with an explicit ALLOW policy (root keys bypass all Turnkey policies)"
|
|
18046
|
+
} : {
|
|
18047
|
+
name: "[wallet] turnkey credentials",
|
|
18048
|
+
status: FAIL,
|
|
18049
|
+
detail: `missing: ${missing.join(", ")} \u2014 set them in .studio/.env.local (Turnkey dashboard \u2192 API keys / settings / wallet account)`
|
|
18050
|
+
}
|
|
18051
|
+
);
|
|
18052
|
+
const signWith = String(process.env.TURNKEY_SIGN_WITH ?? "").trim();
|
|
18053
|
+
if (signWith !== "" && !TURNKEY_ADDRESS_RE.test(signWith)) {
|
|
18054
|
+
out.push({
|
|
18055
|
+
name: "TURNKEY_SIGN_WITH format",
|
|
18056
|
+
status: FAIL,
|
|
18057
|
+
detail: "must be the wallet account's Ethereum address (0x + 40 hex chars), not a Turnkey wallet id \u2014 copy it from the dashboard wallet-account view"
|
|
18058
|
+
});
|
|
18059
|
+
}
|
|
18060
|
+
const anchored = String(walletCfg.address ?? "").trim();
|
|
18061
|
+
if (anchored === "") {
|
|
18062
|
+
out.push({
|
|
18063
|
+
name: "[wallet] address anchor",
|
|
18064
|
+
status: WARN,
|
|
18065
|
+
detail: "no [wallet].address \u2014 run `bag wallet new` to adopt TURNKEY_SIGN_WITH"
|
|
18066
|
+
});
|
|
18067
|
+
} else if (signWith !== "" && TURNKEY_ADDRESS_RE.test(signWith)) {
|
|
18068
|
+
const matches = anchored.toLowerCase() === signWith.toLowerCase();
|
|
18069
|
+
out.push(
|
|
18070
|
+
matches ? {
|
|
18071
|
+
name: "[wallet] address anchor",
|
|
18072
|
+
status: PASS,
|
|
18073
|
+
detail: `${anchored} matches TURNKEY_SIGN_WITH`
|
|
18074
|
+
} : {
|
|
18075
|
+
name: "[wallet] address anchor",
|
|
18076
|
+
status: FAIL,
|
|
18077
|
+
detail: `[wallet].address ${anchored} does not match TURNKEY_SIGN_WITH ${signWith} \u2014 stale anchor or different Turnkey credentials; fix .studio/.env.local, then re-run \`bag wallet new\``
|
|
18078
|
+
}
|
|
18079
|
+
);
|
|
18080
|
+
}
|
|
18081
|
+
return out;
|
|
18082
|
+
}
|
|
18083
|
+
async function checkWalletAltana(walletCfg, projectRoot, data) {
|
|
17742
18084
|
const out = [];
|
|
17743
18085
|
const contracts = erc8183ContractOverrideState(
|
|
17744
18086
|
erc8183ContractEnvForProject(projectRoot)
|
|
@@ -17824,13 +18166,41 @@ function checkWalletAltana(walletCfg, projectRoot, data) {
|
|
|
17824
18166
|
out.push({
|
|
17825
18167
|
name: "[wallet] Altana SDK",
|
|
17826
18168
|
status: entry === null ? FAIL : PASS,
|
|
17827
|
-
detail: entry === null ? "@altananetwork/sdk is not resolvable from this project \u2014 run `pnpm add @altananetwork/sdk@0.
|
|
18169
|
+
detail: entry === null ? "@altananetwork/sdk is not resolvable from this project \u2014 run `pnpm add @altananetwork/sdk@0.7.1`" : entry
|
|
17828
18170
|
});
|
|
17829
18171
|
} catch (error) {
|
|
17830
18172
|
out.push({
|
|
17831
18173
|
name: "[wallet] Altana SDK",
|
|
17832
18174
|
status: FAIL,
|
|
17833
|
-
detail: `${error instanceof Error ? error.message : String(error)} \u2014 run \`pnpm add @altananetwork/sdk@0.
|
|
18175
|
+
detail: `${error instanceof Error ? error.message : String(error)} \u2014 run \`pnpm add @altananetwork/sdk@0.7.1\``
|
|
18176
|
+
});
|
|
18177
|
+
}
|
|
18178
|
+
const networkName = String(tableOf14(data, "network").default ?? "bsc-mainnet");
|
|
18179
|
+
try {
|
|
18180
|
+
const allowanceRaw = await readUAllowanceRaw(
|
|
18181
|
+
address,
|
|
18182
|
+
PERMIT2_ADDRESS,
|
|
18183
|
+
networkName
|
|
18184
|
+
);
|
|
18185
|
+
if (allowanceRaw !== null) {
|
|
18186
|
+
const uToken = getNetwork9(networkName).token("U");
|
|
18187
|
+
out.push(
|
|
18188
|
+
allowanceRaw > 0n ? {
|
|
18189
|
+
name: "[wallet] Altana x402 buying",
|
|
18190
|
+
status: PASS,
|
|
18191
|
+
detail: `U\u2192Permit2 allowance ${fromRaw3(allowanceRaw, uToken.decimals)} U on ${networkName} (b402 permit2 rail armed)`
|
|
18192
|
+
} : {
|
|
18193
|
+
name: "[wallet] Altana x402 buying",
|
|
18194
|
+
status: WARN,
|
|
18195
|
+
detail: `no U\u2192Permit2 allowance on ${networkName} \u2014 outbound x402 buying is not armed; run \`bag wallet session x402-setup --allowance-u <amount>\` (admin key) if this agent should pay b402 merchants`
|
|
18196
|
+
}
|
|
18197
|
+
);
|
|
18198
|
+
}
|
|
18199
|
+
} catch (error) {
|
|
18200
|
+
out.push({
|
|
18201
|
+
name: "[wallet] Altana x402 buying",
|
|
18202
|
+
status: WARN,
|
|
18203
|
+
detail: `could not read the U\u2192Permit2 allowance on ${networkName}: ${error instanceof Error ? error.message : String(error)}`
|
|
17834
18204
|
});
|
|
17835
18205
|
}
|
|
17836
18206
|
return out;
|
|
@@ -17930,6 +18300,20 @@ function checkPassword(data) {
|
|
|
17930
18300
|
}
|
|
17931
18301
|
];
|
|
17932
18302
|
}
|
|
18303
|
+
if (walletKind2 === "turnkey") {
|
|
18304
|
+
const missing = TURNKEY_REQUIRED_ENV.filter((key) => !process.env[key]);
|
|
18305
|
+
return [
|
|
18306
|
+
missing.length === 0 ? {
|
|
18307
|
+
name: "TURNKEY_* env",
|
|
18308
|
+
status: PASS,
|
|
18309
|
+
detail: "all Turnkey credentials set (WALLET_PASSWORD is not used for this kind)"
|
|
18310
|
+
} : {
|
|
18311
|
+
name: "TURNKEY_* env",
|
|
18312
|
+
status: WARN,
|
|
18313
|
+
detail: `missing: ${missing.join(", ")} \u2014 signing will fail (set in .studio/.env.local)`
|
|
18314
|
+
}
|
|
18315
|
+
];
|
|
18316
|
+
}
|
|
17933
18317
|
if (process.env.WALLET_PASSWORD) {
|
|
17934
18318
|
return [{ name: "WALLET_PASSWORD env", status: PASS, detail: "set" }];
|
|
17935
18319
|
}
|
|
@@ -18298,11 +18682,11 @@ function checkX402Seller(data, agentRoot2) {
|
|
|
18298
18682
|
}
|
|
18299
18683
|
];
|
|
18300
18684
|
const walletKind2 = String(tableOf14(data, "wallet").kind ?? "evm-local");
|
|
18301
|
-
if (!["evm-local", "twak"].includes(walletKind2)) {
|
|
18685
|
+
if (!["evm-local", "twak", "turnkey"].includes(walletKind2)) {
|
|
18302
18686
|
out.push({
|
|
18303
18687
|
name: "x402 payout wallet",
|
|
18304
18688
|
status: FAIL,
|
|
18305
|
-
detail: `PAID B402 supports evm-local or
|
|
18689
|
+
detail: `PAID B402 supports evm-local, twak or turnkey, not ${walletKind2}.`
|
|
18306
18690
|
});
|
|
18307
18691
|
}
|
|
18308
18692
|
const credentials = b402Credentials(agentRoot2);
|
|
@@ -18376,7 +18760,7 @@ function checkStorage(data) {
|
|
|
18376
18760
|
}
|
|
18377
18761
|
function balanceAddress(projectRoot, data) {
|
|
18378
18762
|
const walletCfg = tableOf14(data, "wallet");
|
|
18379
|
-
if (walletCfg.kind === "twak" || walletCfg.kind === "altana") {
|
|
18763
|
+
if (walletCfg.kind === "twak" || walletCfg.kind === "altana" || walletCfg.kind === "turnkey") {
|
|
18380
18764
|
const addr = String(walletCfg.address ?? "").trim();
|
|
18381
18765
|
return addr || null;
|
|
18382
18766
|
}
|
|
@@ -21230,16 +21614,21 @@ async function cmdSellStatus(probe) {
|
|
|
21230
21614
|
}
|
|
21231
21615
|
try {
|
|
21232
21616
|
const supported = await _probeB402Supported(process.env);
|
|
21233
|
-
const
|
|
21234
|
-
(kind) => kind.x402Version === 2 && kind.scheme === "exact" && kind.network === network && kind.extra.assetTransferMethod ===
|
|
21617
|
+
const matching = (method) => supported?.kinds.find(
|
|
21618
|
+
(kind) => kind.x402Version === 2 && kind.scheme === "exact" && kind.network === network && kind.extra.assetTransferMethod === method && kind.extra.name === token.eip712Name && kind.extra.version === token.eip712Version
|
|
21619
|
+
);
|
|
21620
|
+
const available = token.methods.filter(
|
|
21621
|
+
(method) => matching(method) !== void 0
|
|
21235
21622
|
);
|
|
21236
|
-
if (
|
|
21237
|
-
|
|
21623
|
+
if (available.length > 0) {
|
|
21624
|
+
const missing = token.methods.filter((m) => !available.includes(m));
|
|
21625
|
+
printOut(
|
|
21626
|
+
`B402 probe: exact U available for ${network} (${available.join(", ")})${missing.length > 0 ? ` \u2014 advertised but not offered by the facilitator: ${missing.join(", ")}` : ""}`
|
|
21627
|
+
);
|
|
21238
21628
|
return 0;
|
|
21239
21629
|
}
|
|
21240
|
-
const observed = methodKind ? `observed name=${String(methodKind.extra.name ?? "(missing)")} version=${String(methodKind.extra.version ?? "(missing)")}` : "no exact/eip3009 kind was returned";
|
|
21241
21630
|
printOut(
|
|
21242
|
-
`B402 probe: mismatch for ${network}; expected name=${token.eip712Name} version=${token.eip712Version};
|
|
21631
|
+
`B402 probe: mismatch for ${network}; expected an exact kind (${token.methods.join(" or ")}) with name=${token.eip712Name} version=${token.eip712Version}; none was returned. Check that the credentials belong to the matching B402 environment.`
|
|
21243
21632
|
);
|
|
21244
21633
|
} catch {
|
|
21245
21634
|
printOut(
|
|
@@ -21368,6 +21757,30 @@ async function cmdBuy2(url, opts) {
|
|
|
21368
21757
|
);
|
|
21369
21758
|
return 1;
|
|
21370
21759
|
}
|
|
21760
|
+
const buyWalletKind = String(tableOf16(cfg, "wallet").kind ?? "evm-local");
|
|
21761
|
+
if (buyWalletKind === "altana") {
|
|
21762
|
+
let allowanceRaw;
|
|
21763
|
+
try {
|
|
21764
|
+
allowanceRaw = await readUAllowanceRaw(
|
|
21765
|
+
wallet.address,
|
|
21766
|
+
PERMIT2_ADDRESS,
|
|
21767
|
+
networkName
|
|
21768
|
+
);
|
|
21769
|
+
} catch (exc) {
|
|
21770
|
+
printErr(`error: permit2 allowance check failed: ${errMsg6(exc)}`);
|
|
21771
|
+
return 1;
|
|
21772
|
+
}
|
|
21773
|
+
if (allowanceRaw !== null && allowanceRaw < neededRaw) {
|
|
21774
|
+
const uToken = getNetwork11(networkName).token("U");
|
|
21775
|
+
printErr(
|
|
21776
|
+
`error: U\u2192Permit2 allowance ${fromRaw5(allowanceRaw, uToken.decimals)} U cannot cover max_usd $${opts.maxUsd.toFixed(2)}: b402 settles Altana payments by pulling through Permit2 (${PERMIT2_ADDRESS}).`
|
|
21777
|
+
);
|
|
21778
|
+
printErr(
|
|
21779
|
+
"fix: bag wallet session x402-setup --allowance-u <amount> (admin key; approves the x402 signature checker and sets the bounded Permit2 allowance)"
|
|
21780
|
+
);
|
|
21781
|
+
return 1;
|
|
21782
|
+
}
|
|
21783
|
+
}
|
|
21371
21784
|
let result;
|
|
21372
21785
|
try {
|
|
21373
21786
|
result = await auditedOp4(
|
|
@@ -21407,7 +21820,7 @@ async function cmdBuy2(url, opts) {
|
|
|
21407
21820
|
}
|
|
21408
21821
|
const paidUsd = result.paidUsd ?? 0;
|
|
21409
21822
|
const envelope = result.txPaymentEnvelope ?? "";
|
|
21410
|
-
const envelopePreview = envelope ? `${envelope.slice(0, 40)}...` : "(no payment \u2014 server did not 402)";
|
|
21823
|
+
const envelopePreview = envelope ? `${envelope.slice(0, 40)}...` : result.paidUsd !== null ? "(delegated x402 client \u2014 the envelope never leaves the wallet client)" : "(no payment \u2014 server did not 402)";
|
|
21411
21824
|
const ok = result.statusCode >= 200 && result.statusCode < 300;
|
|
21412
21825
|
if (result.paidUsd === null) {
|
|
21413
21826
|
if (ok) {
|