@lawrenceliang-btc/atel-sdk 1.1.20 → 1.1.22

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/bin/atel.mjs CHANGED
@@ -5614,6 +5614,45 @@ async function signedFetch(method, path, payload = {}) {
5614
5614
  return data;
5615
5615
  }
5616
5616
 
5617
+ // ─── Auth Command ────────────────────────────────────────────────
5618
+
5619
+ async function cmdAuth(code) {
5620
+ if (!code) {
5621
+ console.error('Usage: atel auth <code>');
5622
+ console.error(' Authorize a Dashboard session using the code displayed on the login page.');
5623
+ process.exit(1);
5624
+ }
5625
+ const id = requireIdentity();
5626
+ const { default: nacl } = await import('tweetnacl');
5627
+ const { serializePayload } = await import('@lawrenceliang-btc/atel-sdk');
5628
+
5629
+ const ts = new Date().toISOString();
5630
+ const payload = { code: code.toUpperCase(), did: id.did, timestamp: ts };
5631
+ const signable = serializePayload({ payload, did: id.did, timestamp: ts });
5632
+ const sig = Buffer.from(nacl.sign.detached(Buffer.from(signable), id.secretKey)).toString('base64');
5633
+
5634
+ try {
5635
+ const resp = await fetch(`${ATEL_PLATFORM}/auth/v1/verify`, {
5636
+ method: 'POST',
5637
+ headers: { 'Content-Type': 'application/json' },
5638
+ body: JSON.stringify({ code: code.toUpperCase(), did: id.did, signature: sig, timestamp: ts }),
5639
+ });
5640
+ const data = await resp.json();
5641
+ if (resp.ok) {
5642
+ console.log('Authorization successful!');
5643
+ console.log(` Agent: ${data.name}`);
5644
+ console.log(` DID: ${data.did}`);
5645
+ console.log(' Dashboard is now connected to your agent.');
5646
+ } else {
5647
+ console.error(`Authorization failed: ${data.error}`);
5648
+ process.exit(1);
5649
+ }
5650
+ } catch (e) {
5651
+ console.error(`Failed to connect: ${e.message}`);
5652
+ process.exit(1);
5653
+ }
5654
+ }
5655
+
5617
5656
  // ─── Account Commands ────────────────────────────────────────────
5618
5657
 
5619
5658
  async function cmdBalance() {
@@ -5772,7 +5811,9 @@ async function cmdTradeTask(capability, description) {
5772
5811
  while (Date.now() - startTime < timeout) {
5773
5812
  await new Promise(r => setTimeout(r, 3000));
5774
5813
  try {
5775
- const info = await signedFetch('GET', `/trade/v1/order/${orderId}`);
5814
+ const pollResp = await fetch(`${PLATFORM_URL}/trade/v1/order/${orderId}`, { signal: AbortSignal.timeout(10000) });
5815
+ if (!pollResp.ok) throw new Error(`HTTP ${pollResp.status}`);
5816
+ const info = await pollResp.json();
5776
5817
  if (info.status !== lastStatus) {
5777
5818
  console.error(`[trade-task] Status: ${lastStatus} → ${info.status}`);
5778
5819
  lastStatus = info.status;
@@ -8056,6 +8097,8 @@ const commands = {
8056
8097
  console.error(' status [--json]');
8057
8098
  process.exit(1);
8058
8099
  },
8100
+ // Auth (Dashboard authorization code login)
8101
+ auth: () => cmdAuth(args[0]),
8059
8102
  // Send (Rich Media P2P Message)
8060
8103
  send: () => {
8061
8104
  if (rawArgs.includes('--help') || rawArgs.includes('-h') || args.length === 0) {
@@ -8253,6 +8296,9 @@ Protocol Commands:
8253
8296
  audit <did_or_url> <taskId> Deep audit: fetch trace + verify hash chain
8254
8297
  rotate Rotate identity key pair (backup + on-chain anchor)
8255
8298
 
8299
+ Auth Commands:
8300
+ auth <code> Authorize Dashboard login (enter code from login page)
8301
+
8256
8302
  Account Commands:
8257
8303
  balance Show platform account balance
8258
8304
  deposit <amount> [channel] Deposit funds (channel: manual|crypto_solana|crypto_base|crypto_bsc|stripe|alipay)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lawrenceliang-btc/atel-sdk",
3
- "version": "1.1.20",
3
+ "version": "1.1.22",
4
4
  "description": "ATEL Protocol SDK - Agent Trust & Exchange Layer",
5
5
  "repository": {
6
6
  "type": "git",
@@ -520,6 +520,18 @@ atel notify enable <id> # 恢复通知
520
520
  atel notify test # 发送测试通知
521
521
  ```
522
522
 
523
+ ## Dashboard 授权
524
+
525
+ 用户可能会发给你一个 6 位授权码(如 `A7K3M9`),要求你连接 Dashboard。收到后直接执行:
526
+
527
+ ```bash
528
+ cd ~/atel-workspace && atel auth <授权码>
529
+ ```
530
+
531
+ 成功后告诉用户"Dashboard 已连接"。
532
+
533
+ ---
534
+
523
535
  ## 重要规则
524
536
 
525
537
  1. **所有 atel 命令必须在 ~/atel-workspace 目录执行**