@run402/sdk 1.57.3 → 1.57.5
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/dist/namespaces/admin.d.ts +6 -5
- package/dist/namespaces/admin.d.ts.map +1 -1
- package/dist/namespaces/admin.js +5 -4
- package/dist/namespaces/admin.js.map +1 -1
- package/package.json +1 -1
- package/core-dist/wallet-auth.d.ts +0 -15
- package/core-dist/wallet-auth.js +0 -62
- package/core-dist/wallet.d.ts +0 -10
- package/core-dist/wallet.js +0 -25
|
@@ -27,8 +27,8 @@ export interface AdminProjectFinanceOptions {
|
|
|
27
27
|
window?: AdminFinanceWindow;
|
|
28
28
|
/**
|
|
29
29
|
* Optional admin session cookie header. Node operators can pass the value of
|
|
30
|
-
* RUN402_ADMIN_COOKIE
|
|
31
|
-
* headers
|
|
30
|
+
* RUN402_ADMIN_COOKIE when they want browser-session auth; otherwise the
|
|
31
|
+
* credential provider's normal auth headers are used.
|
|
32
32
|
*/
|
|
33
33
|
cookie?: string;
|
|
34
34
|
}
|
|
@@ -63,9 +63,10 @@ export declare class Admin {
|
|
|
63
63
|
* Fetch per-project finance for platform operators.
|
|
64
64
|
*
|
|
65
65
|
* This is the same admin-only surface used by the Run402 Finance tab. It is
|
|
66
|
-
* gated by
|
|
67
|
-
*
|
|
68
|
-
* credential provider whose `getAuth()` returns
|
|
66
|
+
* gated by platform-admin auth; project service keys are not sufficient.
|
|
67
|
+
* Use the Node SDK with an admin allowance wallet, pass `cookie` for browser
|
|
68
|
+
* session auth, or provide a credential provider whose `getAuth()` returns
|
|
69
|
+
* suitable admin headers.
|
|
69
70
|
*/
|
|
70
71
|
getProjectFinance(projectId: string, opts?: AdminProjectFinanceOptions): Promise<AdminProjectFinanceResult>;
|
|
71
72
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"admin.d.ts","sourceRoot":"","sources":["../../src/namespaces/admin.ts"],"names":[],"mappings":"AAAA;;;;;;GAM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BAAiB,EAAE;QACjB,oBAAoB,EAAE,MAAM,CAAC;QAC7B,sBAAsB,EAAE,MAAM,CAAC;QAC/B,qBAAqB,EAAE,MAAM,CAAC;QAC9B,wBAAwB,EAAE,MAAM,CAAC;QACjC,uBAAuB,EAAE,MAAM,CAAC;KACjC,CAAC;IACF,qBAAqB,EAAE,KAAK,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC5E,KAAK,EAAE,MAAM,CAAC;CACf;AAID,qBAAa,KAAK;IACJ,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,MAAM;IAE3C,wEAAwE;IAClE,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAQ9D,0DAA0D;IACpD,eAAe,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAYzE;;;;;;;;OAQG;IACG,iBAAiB,CACrB,SAAS,EAAE,MAAM,EACjB,IAAI,GAAE,0BAA+B,GACpC,OAAO,CAAC,yBAAyB,CAAC;CAoBtC"}
|
package/dist/namespaces/admin.js
CHANGED
|
@@ -37,16 +37,17 @@ export class Admin {
|
|
|
37
37
|
* Fetch per-project finance for platform operators.
|
|
38
38
|
*
|
|
39
39
|
* This is the same admin-only surface used by the Run402 Finance tab. It is
|
|
40
|
-
* gated by
|
|
41
|
-
*
|
|
42
|
-
* credential provider whose `getAuth()` returns
|
|
40
|
+
* gated by platform-admin auth; project service keys are not sufficient.
|
|
41
|
+
* Use the Node SDK with an admin allowance wallet, pass `cookie` for browser
|
|
42
|
+
* session auth, or provide a credential provider whose `getAuth()` returns
|
|
43
|
+
* suitable admin headers.
|
|
43
44
|
*/
|
|
44
45
|
async getProjectFinance(projectId, opts = {}) {
|
|
45
46
|
const window = opts.window ?? "30d";
|
|
46
47
|
if (!FINANCE_WINDOWS.has(window)) {
|
|
47
48
|
throw new LocalError(`Invalid finance window: ${String(window)}. Expected one of: 24h, 7d, 30d, 90d.`, "fetching project finance");
|
|
48
49
|
}
|
|
49
|
-
const headers = {};
|
|
50
|
+
const headers = { "X-Admin-Mode": "1" };
|
|
50
51
|
if (opts.cookie)
|
|
51
52
|
headers.Cookie = opts.cookie;
|
|
52
53
|
return this.client.request(`/admin/api/finance/project/${encodeURIComponent(projectId)}?window=${encodeURIComponent(window)}`, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"admin.js","sourceRoot":"","sources":["../../src/namespaces/admin.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAmD1C,MAAM,eAAe,GAAG,IAAI,GAAG,CAAqB,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;AAEjF,MAAM,OAAO,KAAK;IACa;IAA7B,YAA6B,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;IAAG,CAAC;IAE/C,wEAAwE;IACxE,KAAK,CAAC,WAAW,CAAC,OAAe;QAC/B,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAoB,aAAa,EAAE;YAC3D,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,EAAE,OAAO,EAAE;YACjB,OAAO,EAAE,iBAAiB;SAC3B,CAAC,CAAC;IACL,CAAC;IAED,0DAA0D;IAC1D,KAAK,CAAC,eAAe,CAAC,OAAqB;QACzC,MAAM,IAAI,GAA2B,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC;QAC5D,IAAI,OAAO,CAAC,KAAK;YAAE,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC9C,IAAI,OAAO,CAAC,OAAO;YAAE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAEpD,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAqB,mBAAmB,EAAE;Y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,CAAC,MAAM,IAAI,KAAK,CAAC;QACpC,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YACjC,MAAM,IAAI,UAAU,CAClB,2BAA2B,MAAM,CAAC,MAAM,CAAC,uCAAuC,EAChF,0BAA0B,CAC3B,CAAC;QACJ,CAAC;QAED,MAAM,OAAO,GAA2B,EAAE,cAAc,EAAE,GAAG,EAAE,CAAC;QAChE,IAAI,IAAI,CAAC,MAAM;YAAE,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAE9C,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CACxB,8BAA8B,kBAAkB,CAAC,SAAS,CAAC,WAAW,kBAAkB,CAAC,MAAM,CAAC,EAAE,EAClG;YACE,OAAO;YACP,OAAO,EAAE,0BAA0B;SACpC,CACF,CAAC;IACJ,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@run402/sdk",
|
|
3
|
-
"version": "1.57.
|
|
3
|
+
"version": "1.57.5",
|
|
4
4
|
"description": "Typed TypeScript client for the Run402 API. Kernel shared by the run402-mcp server, the run402 CLI, and user-deployed run402 functions.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Wallet auth helper — generates EIP-191 signature headers for Run402 API.
|
|
3
|
-
* Uses @noble/curves (lighter than viem) for signing.
|
|
4
|
-
*/
|
|
5
|
-
export interface WalletAuthHeaders {
|
|
6
|
-
"X-Run402-Wallet": string;
|
|
7
|
-
"X-Run402-Signature": string;
|
|
8
|
-
"X-Run402-Timestamp": string;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Get wallet auth headers for the Run402 API.
|
|
12
|
-
* Returns null if no wallet is configured.
|
|
13
|
-
*/
|
|
14
|
-
export declare function getWalletAuthHeaders(walletPath?: string): WalletAuthHeaders | null;
|
|
15
|
-
//# sourceMappingURL=wallet-auth.d.ts.map
|
package/core-dist/wallet-auth.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Wallet auth helper — generates EIP-191 signature headers for Run402 API.
|
|
3
|
-
* Uses @noble/curves (lighter than viem) for signing.
|
|
4
|
-
*/
|
|
5
|
-
import { secp256k1 } from "@noble/curves/secp256k1.js";
|
|
6
|
-
import { keccak_256 } from "@noble/hashes/sha3.js";
|
|
7
|
-
import { bytesToHex } from "@noble/hashes/utils.js";
|
|
8
|
-
import { readWallet } from "./wallet.js";
|
|
9
|
-
/**
|
|
10
|
-
* EIP-191 personal_sign: sign a message with the wallet's private key.
|
|
11
|
-
*/
|
|
12
|
-
function personalSign(privateKeyHex, address, message) {
|
|
13
|
-
const msgBytes = new TextEncoder().encode(message);
|
|
14
|
-
const prefix = new TextEncoder().encode(`\x19Ethereum Signed Message:\n${msgBytes.length}`);
|
|
15
|
-
const prefixed = new Uint8Array(prefix.length + msgBytes.length);
|
|
16
|
-
prefixed.set(prefix);
|
|
17
|
-
prefixed.set(msgBytes, prefix.length);
|
|
18
|
-
const hash = keccak_256(prefixed);
|
|
19
|
-
const pkHex = privateKeyHex.startsWith("0x")
|
|
20
|
-
? privateKeyHex.slice(2)
|
|
21
|
-
: privateKeyHex;
|
|
22
|
-
const pkBytes = Uint8Array.from(Buffer.from(pkHex, "hex"));
|
|
23
|
-
const rawSig = secp256k1.sign(hash, pkBytes);
|
|
24
|
-
const sig = secp256k1.Signature.fromBytes(rawSig);
|
|
25
|
-
// Determine recovery bit by trying both and matching the address
|
|
26
|
-
let recovery = 0;
|
|
27
|
-
for (const v of [0, 1]) {
|
|
28
|
-
try {
|
|
29
|
-
const recovered = sig.addRecoveryBit(v).recoverPublicKey(hash);
|
|
30
|
-
const pubBytes = recovered.toBytes(false).slice(1); // uncompressed, drop 04 prefix
|
|
31
|
-
const addrBytes = keccak_256(pubBytes).slice(-20);
|
|
32
|
-
if ("0x" + bytesToHex(addrBytes) === address.toLowerCase()) {
|
|
33
|
-
recovery = v;
|
|
34
|
-
break;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
catch {
|
|
38
|
-
continue;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
const r = sig.r.toString(16).padStart(64, "0");
|
|
42
|
-
const s = sig.s.toString(16).padStart(64, "0");
|
|
43
|
-
const vHex = (recovery + 27).toString(16).padStart(2, "0");
|
|
44
|
-
return "0x" + r + s + vHex;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Get wallet auth headers for the Run402 API.
|
|
48
|
-
* Returns null if no wallet is configured.
|
|
49
|
-
*/
|
|
50
|
-
export function getWalletAuthHeaders(walletPath) {
|
|
51
|
-
const wallet = readWallet(walletPath);
|
|
52
|
-
if (!wallet || !wallet.address || !wallet.privateKey)
|
|
53
|
-
return null;
|
|
54
|
-
const timestamp = Math.floor(Date.now() / 1000).toString();
|
|
55
|
-
const signature = personalSign(wallet.privateKey, wallet.address, `run402:${timestamp}`);
|
|
56
|
-
return {
|
|
57
|
-
"X-Run402-Wallet": wallet.address,
|
|
58
|
-
"X-Run402-Signature": signature,
|
|
59
|
-
"X-Run402-Timestamp": timestamp,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
//# sourceMappingURL=wallet-auth.js.map
|
package/core-dist/wallet.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export interface WalletData {
|
|
2
|
-
address: string;
|
|
3
|
-
privateKey: string;
|
|
4
|
-
created?: string;
|
|
5
|
-
funded?: boolean;
|
|
6
|
-
lastFaucet?: string;
|
|
7
|
-
}
|
|
8
|
-
export declare function readWallet(path?: string): WalletData | null;
|
|
9
|
-
export declare function saveWallet(data: WalletData, path?: string): void;
|
|
10
|
-
//# sourceMappingURL=wallet.d.ts.map
|
package/core-dist/wallet.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { readFileSync, writeFileSync, mkdirSync, existsSync, chmodSync, renameSync } from "node:fs";
|
|
2
|
-
import { dirname, join } from "node:path";
|
|
3
|
-
import { randomBytes } from "node:crypto";
|
|
4
|
-
import { getWalletPath } from "./config.js";
|
|
5
|
-
export function readWallet(path) {
|
|
6
|
-
const p = path ?? getWalletPath();
|
|
7
|
-
if (!existsSync(p))
|
|
8
|
-
return null;
|
|
9
|
-
try {
|
|
10
|
-
return JSON.parse(readFileSync(p, "utf-8"));
|
|
11
|
-
}
|
|
12
|
-
catch {
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
export function saveWallet(data, path) {
|
|
17
|
-
const p = path ?? getWalletPath();
|
|
18
|
-
const dir = dirname(p);
|
|
19
|
-
mkdirSync(dir, { recursive: true });
|
|
20
|
-
const tmp = join(dir, `.wallet.${randomBytes(4).toString("hex")}.tmp`);
|
|
21
|
-
writeFileSync(tmp, JSON.stringify(data, null, 2), { mode: 0o600 });
|
|
22
|
-
renameSync(tmp, p);
|
|
23
|
-
chmodSync(p, 0o600);
|
|
24
|
-
}
|
|
25
|
-
//# sourceMappingURL=wallet.js.map
|