@daski/pay 0.1.0
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 +21 -0
- package/README.md +102 -0
- package/dist/bin/daski.d.ts +3 -0
- package/dist/bin/daski.d.ts.map +1 -0
- package/dist/bin/daski.js +187 -0
- package/dist/bin/daski.js.map +1 -0
- package/dist/cli/args.d.ts +11 -0
- package/dist/cli/args.d.ts.map +1 -0
- package/dist/cli/args.js +82 -0
- package/dist/cli/args.js.map +1 -0
- package/dist/cli/errors.d.ts +24 -0
- package/dist/cli/errors.d.ts.map +1 -0
- package/dist/cli/errors.js +23 -0
- package/dist/cli/errors.js.map +1 -0
- package/dist/cli/output.d.ts +8 -0
- package/dist/cli/output.d.ts.map +1 -0
- package/dist/cli/output.js +76 -0
- package/dist/cli/output.js.map +1 -0
- package/dist/cli/prompt.d.ts +12 -0
- package/dist/cli/prompt.d.ts.map +1 -0
- package/dist/cli/prompt.js +101 -0
- package/dist/cli/prompt.js.map +1 -0
- package/dist/cli/redact.d.ts +26 -0
- package/dist/cli/redact.d.ts.map +1 -0
- package/dist/cli/redact.js +55 -0
- package/dist/cli/redact.js.map +1 -0
- package/dist/commands/buy.d.ts +15 -0
- package/dist/commands/buy.d.ts.map +1 -0
- package/dist/commands/buy.js +276 -0
- package/dist/commands/buy.js.map +1 -0
- package/dist/commands/doctor.d.ts +29 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +173 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/order.d.ts +18 -0
- package/dist/commands/order.d.ts.map +1 -0
- package/dist/commands/order.js +256 -0
- package/dist/commands/order.js.map +1 -0
- package/dist/commands/signPayment.d.ts +10 -0
- package/dist/commands/signPayment.d.ts.map +1 -0
- package/dist/commands/signPayment.js +162 -0
- package/dist/commands/signPayment.js.map +1 -0
- package/dist/commands/wallet.d.ts +11 -0
- package/dist/commands/wallet.d.ts.map +1 -0
- package/dist/commands/wallet.js +104 -0
- package/dist/commands/wallet.js.map +1 -0
- package/dist/config.d.ts +64 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +200 -0
- package/dist/config.js.map +1 -0
- package/dist/context.d.ts +36 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +54 -0
- package/dist/context.js.map +1 -0
- package/dist/gateway/balance.d.ts +16 -0
- package/dist/gateway/balance.d.ts.map +1 -0
- package/dist/gateway/balance.js +23 -0
- package/dist/gateway/balance.js.map +1 -0
- package/dist/gateway/catalog.d.ts +49 -0
- package/dist/gateway/catalog.d.ts.map +1 -0
- package/dist/gateway/catalog.js +161 -0
- package/dist/gateway/catalog.js.map +1 -0
- package/dist/gateway/client.d.ts +80 -0
- package/dist/gateway/client.d.ts.map +1 -0
- package/dist/gateway/client.js +128 -0
- package/dist/gateway/client.js.map +1 -0
- package/dist/gateway/lifecycle.d.ts +45 -0
- package/dist/gateway/lifecycle.d.ts.map +1 -0
- package/dist/gateway/lifecycle.js +96 -0
- package/dist/gateway/lifecycle.js.map +1 -0
- package/dist/gateway/purchase.d.ts +119 -0
- package/dist/gateway/purchase.d.ts.map +1 -0
- package/dist/gateway/purchase.js +250 -0
- package/dist/gateway/purchase.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/paths.d.ts +6 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +11 -0
- package/dist/paths.js.map +1 -0
- package/dist/signers/cdp.d.ts +7 -0
- package/dist/signers/cdp.d.ts.map +1 -0
- package/dist/signers/cdp.js +42 -0
- package/dist/signers/cdp.js.map +1 -0
- package/dist/signers/circle.d.ts +53 -0
- package/dist/signers/circle.d.ts.map +1 -0
- package/dist/signers/circle.js +136 -0
- package/dist/signers/circle.js.map +1 -0
- package/dist/signers/index.d.ts +23 -0
- package/dist/signers/index.d.ts.map +1 -0
- package/dist/signers/index.js +22 -0
- package/dist/signers/index.js.map +1 -0
- package/dist/signers/local.d.ts +3 -0
- package/dist/signers/local.d.ts.map +1 -0
- package/dist/signers/local.js +24 -0
- package/dist/signers/local.js.map +1 -0
- package/dist/signers/selfTest.d.ts +46 -0
- package/dist/signers/selfTest.d.ts.map +1 -0
- package/dist/signers/selfTest.js +113 -0
- package/dist/signers/selfTest.js.map +1 -0
- package/dist/store/keystore.d.ts +19 -0
- package/dist/store/keystore.d.ts.map +1 -0
- package/dist/store/keystore.js +226 -0
- package/dist/store/keystore.js.map +1 -0
- package/dist/store/orders.d.ts +39 -0
- package/dist/store/orders.d.ts.map +1 -0
- package/dist/store/orders.js +91 -0
- package/dist/store/orders.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +21 -0
- package/dist/version.js.map +1 -0
- package/package.json +59 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signPayment.js","sourceRoot":"","sources":["../../src/commands/signPayment.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,qBAAqB,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAuB,MAAM,eAAe,CAAC;AAEnE,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACrF,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAUjD,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,OAA2B;IAE3B,MAAM,SAAS,GAAG,aAAa,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IACvD,MAAM,WAAW,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC,CAAE,C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
|
|
|
1
|
+
export interface WalletOptions {
|
|
2
|
+
profile?: string | undefined;
|
|
3
|
+
yesHumanApproved?: boolean;
|
|
4
|
+
signerOverride?: string | undefined;
|
|
5
|
+
cdpAccount?: string | undefined;
|
|
6
|
+
circleWallet?: string | undefined;
|
|
7
|
+
}
|
|
8
|
+
export declare function createWallet(options: WalletOptions): Promise<Record<string, unknown>>;
|
|
9
|
+
export declare function walletAddress(options: WalletOptions): Promise<Record<string, unknown>>;
|
|
10
|
+
export declare function walletBalance(options: WalletOptions): Promise<Record<string, unknown>>;
|
|
11
|
+
//# sourceMappingURL=wallet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/commands/wallet.ts"],"names":[],"mappings":"AAkBA,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACnC;AAID,wBAAsB,YAAY,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAwD3F;AAED,wBAAsB,aAAa,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAgB5F;AAED,wBAAsB,aAAa,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAoB5F"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `daski wallet` — create, address, balance.
|
|
3
|
+
*
|
|
4
|
+
* Creating a key is the one action here that cannot be undone by re-running a
|
|
5
|
+
* command, so it is gated on a human: an interactive terminal and a typed
|
|
6
|
+
* confirmation phrase. `--yes-human-approved` exists for provisioning
|
|
7
|
+
* scripts, and its name is the documentation: whoever passes it is asserting a
|
|
8
|
+
* human approved this.
|
|
9
|
+
*/
|
|
10
|
+
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
|
|
11
|
+
import { getAddress } from "viem";
|
|
12
|
+
import { CliError } from "../cli/errors.js";
|
|
13
|
+
import { confirmPhrase, isInteractive } from "../cli/prompt.js";
|
|
14
|
+
import { loadConfig } from "../config.js";
|
|
15
|
+
import { readBalances } from "../gateway/balance.js";
|
|
16
|
+
import { hasKey, locateKey, storeKey } from "../store/keystore.js";
|
|
17
|
+
import { createSigner } from "../signers/index.js";
|
|
18
|
+
const CREATE_PHRASE = "create a new key";
|
|
19
|
+
export async function createWallet(options) {
|
|
20
|
+
const loaded = loadConfig(options.profile);
|
|
21
|
+
const profileName = loaded.profileName;
|
|
22
|
+
if (await hasKey(profileName)) {
|
|
23
|
+
throw new CliError({
|
|
24
|
+
code: "DASKI_KEY_ALREADY_EXISTS",
|
|
25
|
+
message: `A signing key already exists for the "${profileName}" profile.`,
|
|
26
|
+
remediation: `Use it with \`daski wallet address --profile ${profileName}\`. This CLI ` +
|
|
27
|
+
"has no rotate or overwrite command: replacing a key is a deliberate " +
|
|
28
|
+
"manual act, so an accidental re-run can never strand funds.",
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
if (!options.yesHumanApproved) {
|
|
32
|
+
if (!isInteractive()) {
|
|
33
|
+
throw new CliError({
|
|
34
|
+
code: "DASKI_KEY_CREATION_NEEDS_HUMAN",
|
|
35
|
+
message: "Creating a signing key requires a human, and this session has no terminal.",
|
|
36
|
+
remediation: "Run it from an interactive terminal, or — if a human has approved " +
|
|
37
|
+
`this — re-run with --yes-human-approved.`,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
const approved = await confirmPhrase(`This creates a new signing key for the "${profileName}" profile ` +
|
|
41
|
+
`(${loaded.profile.network}).\n` +
|
|
42
|
+
"The key is stored on this machine and never sent to the gateway.\n" +
|
|
43
|
+
"There is no recovery command: if you lose it, funds held by it are gone.", CREATE_PHRASE);
|
|
44
|
+
if (!approved) {
|
|
45
|
+
throw new CliError({
|
|
46
|
+
code: "DASKI_KEY_CREATION_DECLINED",
|
|
47
|
+
message: "Key creation was not confirmed.",
|
|
48
|
+
remediation: `Re-run and type "${CREATE_PHRASE}" to confirm.`,
|
|
49
|
+
exitCode: 2,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const privateKey = generatePrivateKey();
|
|
54
|
+
const account = privateKeyToAccount(privateKey);
|
|
55
|
+
const location = await storeKey(profileName, privateKey);
|
|
56
|
+
// The address is public; the key is not, and does not appear here or anywhere.
|
|
57
|
+
return {
|
|
58
|
+
created: true,
|
|
59
|
+
profile: profileName,
|
|
60
|
+
address: account.address,
|
|
61
|
+
network: loaded.profile.network,
|
|
62
|
+
storedIn: location.description,
|
|
63
|
+
keyMaterial: "never printed, never logged, never sent to the gateway",
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export async function walletAddress(options) {
|
|
67
|
+
const loaded = loadConfig(options.profile);
|
|
68
|
+
const signer = await createSigner({
|
|
69
|
+
kind: options.signerOverride ?? loaded.profile.signer,
|
|
70
|
+
profile: loaded.profileName,
|
|
71
|
+
cdpAccount: options.cdpAccount,
|
|
72
|
+
circleWallet: options.circleWallet,
|
|
73
|
+
});
|
|
74
|
+
const location = await locateKey(loaded.profileName);
|
|
75
|
+
return {
|
|
76
|
+
profile: loaded.profileName,
|
|
77
|
+
network: loaded.profile.network,
|
|
78
|
+
address: await signer.getAddress(),
|
|
79
|
+
signer: signer.describe().provider,
|
|
80
|
+
keySource: location?.source ?? "unknown",
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
export async function walletBalance(options) {
|
|
84
|
+
const loaded = loadConfig(options.profile);
|
|
85
|
+
const signer = await createSigner({
|
|
86
|
+
kind: options.signerOverride ?? loaded.profile.signer,
|
|
87
|
+
profile: loaded.profileName,
|
|
88
|
+
cdpAccount: options.cdpAccount,
|
|
89
|
+
circleWallet: options.circleWallet,
|
|
90
|
+
});
|
|
91
|
+
const address = getAddress(await signer.getAddress());
|
|
92
|
+
const balances = await readBalances({
|
|
93
|
+
rpcUrl: loaded.profile.rpcUrl,
|
|
94
|
+
address,
|
|
95
|
+
usdcAddress: loaded.profile.usdcAddress,
|
|
96
|
+
});
|
|
97
|
+
return {
|
|
98
|
+
profile: loaded.profileName,
|
|
99
|
+
network: loaded.profile.network,
|
|
100
|
+
address,
|
|
101
|
+
...balances,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=wallet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../src/commands/wallet.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAUnD,MAAM,aAAa,GAAG,kBAAkB,CAAC;AAEzC,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,OAAsB;IACvD,MAAM,MAAM,GAAG,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC3C,MAAM,WAAW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M,CAAC,UAAU,EAAE,CAAC,CAAC;IACtD,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC;QAClC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM;QAC7B,OAAO;QACP,WAAW,EAAE,MAAM,CAAC,OAAO,CAAC,WAAW;KACxC,CAAC,CAAC;IACH,OAAO;QACL,OAAO,EAAE,MAAM,CAAC,WAAW;QAC3B,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO;QAC/B,OAAO;QACP,GAAG,QAAQ;KACZ,CAAC;AACJ,CAAC"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { type Address } from "viem";
|
|
2
|
+
export type ProfileName = "sandbox" | "mainnet" | (string & {});
|
|
3
|
+
export type SignerKind = "local" | "cdp" | "circle";
|
|
4
|
+
export interface ProfileConfig {
|
|
5
|
+
/** Gateway base URL; also the audience for lifecycle signatures. */
|
|
6
|
+
gatewayUrl: string;
|
|
7
|
+
/** CAIP-2 network, e.g. `eip155:84532`. */
|
|
8
|
+
network: string;
|
|
9
|
+
chainId: number;
|
|
10
|
+
/** The only token this profile will ever sign a transfer of. */
|
|
11
|
+
usdcAddress: Address;
|
|
12
|
+
/** EVM RPC used for balance reads. Never for signing. */
|
|
13
|
+
rpcUrl: string;
|
|
14
|
+
/** Human-owned. Not raisable at runtime. */
|
|
15
|
+
maxPerOrderUsdc: string;
|
|
16
|
+
/** Human-owned. Not raisable at runtime. */
|
|
17
|
+
sessionCapUsdc: string;
|
|
18
|
+
/** Human-owned. Above this, a purchase needs an interactive human. */
|
|
19
|
+
requireApprovalAboveUsdc: string;
|
|
20
|
+
signer: SignerKind;
|
|
21
|
+
/** Profiles are opt-in; mainnet ships disabled. */
|
|
22
|
+
enabled: boolean;
|
|
23
|
+
}
|
|
24
|
+
export interface DaskiConfig {
|
|
25
|
+
version: 1;
|
|
26
|
+
defaultProfile: ProfileName;
|
|
27
|
+
profiles: Record<ProfileName, ProfileConfig>;
|
|
28
|
+
}
|
|
29
|
+
/** Base Sepolia USDC — the canonical sandbox token, pinned. */
|
|
30
|
+
export declare const SANDBOX_USDC: `0x${string}`;
|
|
31
|
+
/** Base mainnet USDC, for the scaffolded-but-disabled profile. */
|
|
32
|
+
export declare const MAINNET_USDC: `0x${string}`;
|
|
33
|
+
export declare const DEFAULT_CONFIG: DaskiConfig;
|
|
34
|
+
export interface LoadedConfig {
|
|
35
|
+
config: DaskiConfig;
|
|
36
|
+
profileName: ProfileName;
|
|
37
|
+
profile: ProfileConfig;
|
|
38
|
+
/** Warnings that are not fatal but belong in `doctor` output. */
|
|
39
|
+
warnings: ConfigWarning[];
|
|
40
|
+
}
|
|
41
|
+
export interface ConfigWarning {
|
|
42
|
+
code: string;
|
|
43
|
+
message: string;
|
|
44
|
+
remediation: string;
|
|
45
|
+
}
|
|
46
|
+
declare const DOC = "https://github.com/daski-io/buyer/blob/main/docs/config.md";
|
|
47
|
+
/** Writes the default config if none exists. Returns the path either way. */
|
|
48
|
+
export declare function ensureConfig(): string;
|
|
49
|
+
/**
|
|
50
|
+
* Loads the config and selects a profile. `--profile` and `DASKI_PROFILE`
|
|
51
|
+
* choose *which* human-owned block applies; neither can alter its contents.
|
|
52
|
+
*/
|
|
53
|
+
export declare function loadConfig(profileOverride?: string): LoadedConfig;
|
|
54
|
+
/** Directory and file permission checks, surfaced by `doctor` (§4.2). */
|
|
55
|
+
export declare function permissionWarnings(path: string): ConfigWarning[];
|
|
56
|
+
/** Tightens the config's caps for one invocation. Lowering only (§4.2). */
|
|
57
|
+
export declare function applyCapOverrides(profile: ProfileConfig, overrides: {
|
|
58
|
+
maxPerOrderUsdc?: string | undefined;
|
|
59
|
+
sessionCapUsdc?: string | undefined;
|
|
60
|
+
}): ProfileConfig;
|
|
61
|
+
/** Parses a decimal USDC string into atomic units without floating point. */
|
|
62
|
+
export declare function atomicUsdc(value: string): bigint;
|
|
63
|
+
export { DOC as CONFIG_DOC };
|
|
64
|
+
//# sour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aAAa,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,QAAA,MAAM,GAAG,+DAA+D,CAAC;AAEzE,6EAA6E;AAC7E,wBAAgB,YAAY,IAAI,MAAM,CAUrC;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG,YAAY,CAqCjE;AAED,yEAAyE;AACzE,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,EAAE,CAmBhE;AAyCD,2EAA2E;AAC3E,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,aAAa,EACtB,SAAS,EAAE;IAAE,eAAe,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GACvF,aAAa,CA0Bf;AAMD,6EAA6E;AAC7E,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAGhD;AAED,OAAO,EAAE,GAAG,IAAI,UAAU,EAAE,CAAC"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* §5 — profiles, and §4.2 — caps are human-owned.
|
|
3
|
+
*
|
|
4
|
+
* The three caps live in `~/.daski/config.json` and nowhere else. No flag and
|
|
5
|
+
* no environment variable can raise them; a flag may lower one for a single
|
|
6
|
+
* invocation, which is the only direction that cannot be used to talk an
|
|
7
|
+
* agent into spending more than its operator allowed.
|
|
8
|
+
*
|
|
9
|
+
* Sandbox and mainnet are separate blocks with separate keychain entries, so
|
|
10
|
+
* a misconfigured profile cannot reach across and spend real money.
|
|
11
|
+
*/
|
|
12
|
+
import { mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
13
|
+
import { dirname } from "node:path";
|
|
14
|
+
import { getAddress } from "viem";
|
|
15
|
+
import { CliError } from "./cli/errors.js";
|
|
16
|
+
import { configPath, daskiHome } from "./paths.js";
|
|
17
|
+
/** Base Sepolia USDC — the canonical sandbox token, pinned. */
|
|
18
|
+
export const SANDBOX_USDC = getAddress("0x036CbD53842c5426634e7929541eC2318f3dCF7e");
|
|
19
|
+
/** Base mainnet USDC, for the scaffolded-but-disabled profile. */
|
|
20
|
+
export const MAINNET_USDC = getAddress("0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913");
|
|
21
|
+
export const DEFAULT_CONFIG = {
|
|
22
|
+
version: 1,
|
|
23
|
+
defaultProfile: "sandbox",
|
|
24
|
+
profiles: {
|
|
25
|
+
sandbox: {
|
|
26
|
+
gatewayUrl: "https://sandbox-gateway.daski.io",
|
|
27
|
+
network: "eip155:84532",
|
|
28
|
+
chainId: 84532,
|
|
29
|
+
usdcAddress: SANDBOX_USDC,
|
|
30
|
+
rpcUrl: "https://sepolia.base.org",
|
|
31
|
+
maxPerOrderUsdc: "25.00",
|
|
32
|
+
sessionCapUsdc: "100.00",
|
|
33
|
+
requireApprovalAboveUsdc: "1.00",
|
|
34
|
+
signer: "local",
|
|
35
|
+
enabled: true,
|
|
36
|
+
},
|
|
37
|
+
// Scaffolded, and deliberately off. Enabling it is a human edit.
|
|
38
|
+
mainnet: {
|
|
39
|
+
gatewayUrl: "https://gateway.daski.io",
|
|
40
|
+
network: "eip155:8453",
|
|
41
|
+
chainId: 8453,
|
|
42
|
+
usdcAddress: MAINNET_USDC,
|
|
43
|
+
rpcUrl: "https://mainnet.base.org",
|
|
44
|
+
maxPerOrderUsdc: "0.00",
|
|
45
|
+
sessionCapUsdc: "0.00",
|
|
46
|
+
requireApprovalAboveUsdc: "0.00",
|
|
47
|
+
signer: "local",
|
|
48
|
+
enabled: false,
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
const DOC = "https://github.com/daski-io/buyer/blob/main/docs/config.md";
|
|
53
|
+
/** Writes the default config if none exists. Returns the path either way. */
|
|
54
|
+
export function ensureConfig() {
|
|
55
|
+
const path = configPath();
|
|
56
|
+
try {
|
|
57
|
+
statSync(path);
|
|
58
|
+
return path;
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
|
|
62
|
+
writeFileSync(path, `${JSON.stringify(DEFAULT_CONFIG, null, 2)}\n`, { mode: 0o600 });
|
|
63
|
+
return path;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Loads the config and selects a profile. `--profile` and `DASKI_PROFILE`
|
|
68
|
+
* choose *which* human-owned block applies; neither can alter its contents.
|
|
69
|
+
*/
|
|
70
|
+
export function loadConfig(profileOverride) {
|
|
71
|
+
const path = ensureConfig();
|
|
72
|
+
const warnings = [];
|
|
73
|
+
let parsed;
|
|
74
|
+
try {
|
|
75
|
+
parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
throw new CliError({
|
|
79
|
+
code: "DASKI_CONFIG_UNREADABLE",
|
|
80
|
+
message: `${path} is not valid JSON: ${error.message}`,
|
|
81
|
+
remediation: `Fix the file by hand, or delete it to regenerate defaults. See ${DOC}`,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
warnings.push(...permissionWarnings(path));
|
|
85
|
+
const profileName = profileOverride ?? process.env.DASKI_PROFILE ?? parsed.defaultProfile;
|
|
86
|
+
const profile = parsed.profiles?.[profileName];
|
|
87
|
+
if (!profile) {
|
|
88
|
+
throw new CliError({
|
|
89
|
+
code: "DASKI_PROFILE_NOT_FOUND",
|
|
90
|
+
message: `No profile named "${profileName}" in ${path}.`,
|
|
91
|
+
remediation: `Add the profile to ${path}, or pass --profile with one of: ` +
|
|
92
|
+
`${Object.keys(parsed.profiles ?? {}).join(", ")}. See ${DOC}`,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
if (!profile.enabled) {
|
|
96
|
+
throw new CliError({
|
|
97
|
+
code: "DASKI_PROFILE_DISABLED",
|
|
98
|
+
message: `The "${profileName}" profile is disabled.`,
|
|
99
|
+
remediation: `Enabling a profile — mainnet especially — is a human action: set ` +
|
|
100
|
+
`profiles.${profileName}.enabled to true in ${path} and set real caps. See ${DOC}`,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
assertProfileSane(profileName, profile, path);
|
|
104
|
+
return { config: parsed, profileName, profile, warnings };
|
|
105
|
+
}
|
|
106
|
+
/** Directory and file permission checks, surfaced by `doctor` (§4.2). */
|
|
107
|
+
export function permissionWarnings(path) {
|
|
108
|
+
const warnings = [];
|
|
109
|
+
for (const [target, label] of [[path, "config file"], [daskiHome(), "state directory"]]) {
|
|
110
|
+
try {
|
|
111
|
+
const mode = statSync(target).mode;
|
|
112
|
+
if ((mode & 0o002) !== 0) {
|
|
113
|
+
warnings.push({
|
|
114
|
+
code: "DASKI_CONFIG_WORLD_WRITABLE",
|
|
115
|
+
message: `The ${label} ${target} is world-writable, so any local process can ` +
|
|
116
|
+
"raise your spend caps.",
|
|
117
|
+
remediation: `Run: chmod ${label === "config file" ? "600" : "700"} ${target}`,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
// A missing target is not a permissions problem; other checks report it.
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return warnings;
|
|
126
|
+
}
|
|
127
|
+
function assertProfileSane(name, profile, path) {
|
|
128
|
+
const expectedNetwork = `eip155:${profile.chainId}`;
|
|
129
|
+
if (profile.network !== expectedNetwork) {
|
|
130
|
+
throw new CliError({
|
|
131
|
+
code: "DASKI_PROFILE_INCOHERENT",
|
|
132
|
+
message: `Profile "${name}" sets network ${profile.network} but chainId ${profile.chainId}.`,
|
|
133
|
+
remediation: `Make them agree in ${path} (network must be ${expectedNetwork}). See ${DOC}`,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
for (const cap of ["maxPerOrderUsdc", "sessionCapUsdc", "requireApprovalAboveUsdc"]) {
|
|
137
|
+
if (!/^\d+(\.\d{1,6})?$/.test(profile[cap])) {
|
|
138
|
+
throw new CliError({
|
|
139
|
+
code: "DASKI_PROFILE_CAP_MALFORMED",
|
|
140
|
+
message: `Profile "${name}" has a malformed ${cap}: ${profile[cap]}`,
|
|
141
|
+
remediation: `Set ${cap} to a decimal USDC amount with at most 6 decimals, e.g. "25.00", ` +
|
|
142
|
+
`in ${path}. See ${DOC}#caps`,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
try {
|
|
147
|
+
getAddress(profile.usdcAddress);
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
throw new CliError({
|
|
151
|
+
code: "DASKI_PROFILE_TOKEN_MALFORMED",
|
|
152
|
+
message: `Profile "${name}" has a malformed usdcAddress: ${profile.usdcAddress}`,
|
|
153
|
+
remediation: `Set a checksummed contract address in ${path}. See ${DOC}`,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
if (!/^https:\/\//.test(profile.gatewayUrl)) {
|
|
157
|
+
throw new CliError({
|
|
158
|
+
code: "DASKI_PROFILE_GATEWAY_NOT_HTTPS",
|
|
159
|
+
message: `Profile "${name}" points at a non-HTTPS gateway: ${profile.gatewayUrl}`,
|
|
160
|
+
remediation: `Use an https:// gateway URL in ${path}. See ${DOC}`,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/** Tightens the config's caps for one invocation. Lowering only (§4.2). */
|
|
165
|
+
export function applyCapOverrides(profile, overrides) {
|
|
166
|
+
const tightened = { ...profile };
|
|
167
|
+
for (const cap of ["maxPerOrderUsdc", "sessionCapUsdc"]) {
|
|
168
|
+
const requested = overrides[cap];
|
|
169
|
+
if (requested === undefined)
|
|
170
|
+
continue;
|
|
171
|
+
if (!/^\d+(\.\d{1,6})?$/.test(requested)) {
|
|
172
|
+
throw new CliError({
|
|
173
|
+
code: "DASKI_CAP_OVERRIDE_MALFORMED",
|
|
174
|
+
message: `--${flagFor(cap)} expects a decimal USDC amount, got "${requested}".`,
|
|
175
|
+
remediation: `Pass e.g. --${flagFor(cap)} 5.00`,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
if (atomicUsdc(requested) > atomicUsdc(profile[cap])) {
|
|
179
|
+
throw new CliError({
|
|
180
|
+
code: "DASKI_CAP_OVERRIDE_WOULD_RAISE",
|
|
181
|
+
message: `--${flagFor(cap)} ${requested} is above the configured ${cap} of ` +
|
|
182
|
+
`${profile[cap]}. Flags may lower a cap, never raise one.`,
|
|
183
|
+
remediation: `Raising a cap is a human action: edit ${cap} in ${configPath()} by hand. ` +
|
|
184
|
+
`See ${DOC}#caps`,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
tightened[cap] = requested;
|
|
188
|
+
}
|
|
189
|
+
return tightened;
|
|
190
|
+
}
|
|
191
|
+
function flagFor(cap) {
|
|
192
|
+
return cap === "maxPerOrderUsdc" ? "max-per-order" : "session-cap";
|
|
193
|
+
}
|
|
194
|
+
/** Parses a decimal USDC string into atomic units without floating point. */
|
|
195
|
+
export function atomicUsdc(value) {
|
|
196
|
+
const [whole = "0", fraction = ""] = value.split(".");
|
|
197
|
+
return BigInt(whole) * 1000000n + BigInt(fraction.padEnd(6, "0").slice(0, 6) || "0");
|
|
198
|
+
}
|
|
199
|
+
export { DOC as CONFIG_DOC };
|
|
200
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC3E,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAgB,MAAM,MAAM,CA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ACD,SAAS,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;IAC7B,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,OAAO,CAAC,GAAyC;IACxD,OAAO,GAAG,KAAK,iBAAiB,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,aAAa,CAAC;AACrE,CAAC;AAED,6EAA6E;AAC7E,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,MAAM,CAAC,KAAK,GAAG,GAAG,EAAE,QAAQ,GAAG,EAAE,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACtD,OAAO,MAAM,CAAC,KAAK,CAAC,GAAG,QAAU,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC;AACzF,CAAC;AAED,OAAO,EAAE,GAAG,IAAI,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The per-invocation context every command shares: profile, signer, gateway,
|
|
3
|
+
* catalog, and the assembled PolicyConfig.
|
|
4
|
+
*
|
|
5
|
+
* The PolicyConfig is built here and nowhere else, so there is exactly one
|
|
6
|
+
* place where caps, pins and the session ledger are wired together — and one
|
|
7
|
+
* place to audit that none of them came from a challenge.
|
|
8
|
+
*/
|
|
9
|
+
import type { PolicyConfig, SignerAdapter } from "@daski/x402-scheme";
|
|
10
|
+
import { type Address } from "viem";
|
|
11
|
+
import { type LoadedConfig, type ProfileConfig } from "./config.js";
|
|
12
|
+
import { Catalog } from "./gateway/catalog.js";
|
|
13
|
+
import { GatewayClient, type GatewayCallLog } from "./gateway/client.js";
|
|
14
|
+
export interface ContextOptions {
|
|
15
|
+
profile?: string | undefined;
|
|
16
|
+
/** Lowering only; see §4.2. */
|
|
17
|
+
maxPerOrderUsdc?: string | undefined;
|
|
18
|
+
sessionCapUsdc?: string | undefined;
|
|
19
|
+
signerOverride?: string | undefined;
|
|
20
|
+
cdpAccount?: string | undefined;
|
|
21
|
+
circleWallet?: string | undefined;
|
|
22
|
+
onCall?: ((entry: GatewayCallLog) => void) | undefined;
|
|
23
|
+
}
|
|
24
|
+
export interface CommandContext {
|
|
25
|
+
loaded: LoadedConfig;
|
|
26
|
+
profileName: string;
|
|
27
|
+
profile: ProfileConfig;
|
|
28
|
+
client: GatewayClient;
|
|
29
|
+
catalog: Catalog;
|
|
30
|
+
signer: SignerAdapter;
|
|
31
|
+
payerAddress: Address;
|
|
32
|
+
policy: PolicyConfig;
|
|
33
|
+
close(): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
export declare function createContext(options: ContextOptions): Promise<CommandContext>;
|
|
36
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAc,KAAK,OAAO,EAAE,MAAM,MAAM,CAAC;AAChD,OAAO,EAAiC,KAAK,YAAY,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AACnG,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAIzE,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,+BAA+B;IAC/B,eAAe,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,MAAM,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;CACxD;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,YAAY,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,aAAa,CAAC;IACvB,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,aAAa,CAAC;IACtB,YAAY,EAAE,OAAO,CAAC;IACtB,MAAM,EAAE,YAAY,CAAC;IACrB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED,wBAAsB,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAiDpF"}
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { getAddress } from "viem";
|
|
2
|
+
import { applyCapOverrides, loadConfig } from "./config.js";
|
|
3
|
+
import { Catalog } from "./gateway/catalog.js";
|
|
4
|
+
import { GatewayClient } from "./gateway/client.js";
|
|
5
|
+
import { createSigner } from "./signers/index.js";
|
|
6
|
+
import { authorizedTotalAtomic, findByIntent } from "./store/orders.js";
|
|
7
|
+
export async function createContext(options) {
|
|
8
|
+
const loaded = loadConfig(options.profile);
|
|
9
|
+
const profile = applyCapOverrides(loaded.profile, {
|
|
10
|
+
maxPerOrderUsdc: options.maxPerOrderUsdc,
|
|
11
|
+
sessionCapUsdc: options.sessionCapUsdc,
|
|
12
|
+
});
|
|
13
|
+
const client = new GatewayClient({
|
|
14
|
+
gatewayUrl: profile.gatewayUrl,
|
|
15
|
+
...(options.onCall ? { onCall: options.onCall } : {}),
|
|
16
|
+
});
|
|
17
|
+
const catalog = new Catalog(client);
|
|
18
|
+
const signer = await createSigner({
|
|
19
|
+
kind: options.signerOverride ?? profile.signer,
|
|
20
|
+
profile: loaded.profileName,
|
|
21
|
+
cdpAccount: options.cdpAccount,
|
|
22
|
+
circleWallet: options.circleWallet,
|
|
23
|
+
});
|
|
24
|
+
const payerAddress = getAddress(await signer.getAddress());
|
|
25
|
+
const policy = {
|
|
26
|
+
payerAddress,
|
|
27
|
+
chainId: profile.chainId,
|
|
28
|
+
canonicalToken: getAddress(profile.usdcAddress),
|
|
29
|
+
maxPerOrderUsdc: profile.maxPerOrderUsdc,
|
|
30
|
+
sessionCapUsdc: profile.sessionCapUsdc,
|
|
31
|
+
resolveSplitter: (providerAgentId, outcomeId) => catalog.splitterEvidence(providerAgentId, outcomeId),
|
|
32
|
+
session: {
|
|
33
|
+
// The running total is the on-disk order store, so the cap survives the
|
|
34
|
+
// process that placed the earlier orders.
|
|
35
|
+
spentAtomic: () => authorizedTotalAtomic(loaded.profileName),
|
|
36
|
+
hasOrderFor: (identifier) => {
|
|
37
|
+
const existing = findByIntent(identifier);
|
|
38
|
+
return existing !== undefined && existing.state !== "INTENT_RECORDED";
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
loaded,
|
|
44
|
+
profileName: loaded.profileName,
|
|
45
|
+
profile,
|
|
46
|
+
client,
|
|
47
|
+
catalog,
|
|
48
|
+
signer,
|
|
49
|
+
payerAddress,
|
|
50
|
+
policy,
|
|
51
|
+
close: () => client.close(),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,UAAU,EAAgB,MAAM,MAAM,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAyC,MAAM,aAAa,CAAC;AACnG,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAuB,MAAM,qBAAqB,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AAE,EAAE,CAC9C,OAAO,CAAC,gBAAgB,CAAC,eAAe,EAAE,SAAS,CAAC;QACtD,OAAO,EAAE;YACP,wEAAwE;YACxE,0CAA0C;YAC1C,WAAW,EAAE,GAAG,EAAE,CAAC,qBAAqB,CAAC,MAAM,CAAC,WAAW,CAAC;YAC5D,WAAW,EAAE,CAAC,UAAU,EAAE,EAAE;gBAC1B,MAAM,QAAQ,GAAG,YAAY,CAAC,UAAU,CAAC,CAAC;gBAC1C,OAAO,QAAQ,KAAK,SAAS,IAAI,QAAQ,CAAC,KAAK,KAAK,iBAAiB,CAAC;YACxE,CAAC;SACF;KACF,CAAC;IAEF,OAAO;QACL,MAAM;QACN,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,OAAO;QACP,MAAM;QACN,OAAO;QACP,MAAM;QACN,YAAY;QACZ,MAAM;QACN,KAAK,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE;KAC5B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Balance reads. RPC only, never a signing path.
|
|
3
|
+
*/
|
|
4
|
+
import { type Address } from "viem";
|
|
5
|
+
export interface Balances {
|
|
6
|
+
nativeWei: string;
|
|
7
|
+
native: string;
|
|
8
|
+
usdcAtomic: string;
|
|
9
|
+
usdc: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function readBalances(options: {
|
|
12
|
+
rpcUrl: string;
|
|
13
|
+
address: Address;
|
|
14
|
+
usdcAddress: Address;
|
|
15
|
+
}): Promise<Balances>;
|
|
16
|
+
//# sourceMappingURL=balance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"balance.d.ts","sourceRoot":"","sources":["../../src/gateway/balance.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAmD,KAAK,OAAO,EAAE,MAAM,MAAM,CAAC;AAErF,MAAM,WAAW,QAAQ;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,wBAAsB,YAAY,CAAC,OAAO,EAAE;IAC1C,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;CACtB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAiBpB"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Balance reads. RPC only, never a signing path.
|
|
3
|
+
*/
|
|
4
|
+
import { createPublicClient, erc20Abi, formatUnits, http } from "viem";
|
|
5
|
+
export async function readBalances(options) {
|
|
6
|
+
const client = createPublicClient({ transport: http(options.rpcUrl) });
|
|
7
|
+
const [native, usdc] = await Promise.all([
|
|
8
|
+
client.getBalance({ address: options.address }),
|
|
9
|
+
client.readContract({
|
|
10
|
+
address: options.usdcAddress,
|
|
11
|
+
abi: erc20Abi,
|
|
12
|
+
functionName: "balanceOf",
|
|
13
|
+
args: [options.address],
|
|
14
|
+
}),
|
|
15
|
+
]);
|
|
16
|
+
return {
|
|
17
|
+
nativeWei: native.toString(),
|
|
18
|
+
native: `${formatUnits(native, 18)} ETH`,
|
|
19
|
+
usdcAtomic: usdc.toString(),
|
|
20
|
+
usdc: `${formatUnits(usdc, 6)} USDC`,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=balance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"balance.js","sourceRoot":"","sources":["../../src/gateway/balance.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,WAAW,EAAE,IAAI,EAAgB,MAAM,MAAM,CAAC;AASrF,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,OAIlC;IACC,MAAM,MAAM,GAAG,kBAAkB,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACvE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACvC,MAAM,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC;QAC/C,MAAM,CAAC,YAAY,CAAC;YAClB,OAAO,EAAE,OAAO,CAAC,WAAW;YAC5B,GAAG,EAAE,QAAQ;YACb,YAAY,EAAE,WAAW;YACzB,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC;SACxB,CAAoB;KACtB,CAAC,CAAC;IACH,OAAO;QACL,SAAS,EAAE,MAAM,CAAC,QAAQ,EAAE;QAC5B,MAAM,EAAE,GAAG,WAAW,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM;QACxC,UAAU,EAAE,IAAI,CAAC,QAAQ,EAAE;QAC3B,IAAI,EAAE,GAAG,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO;KACrC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type Address } from "viem";
|
|
2
|
+
import type { SplitterEvidence } from "@daski/x402-scheme";
|
|
3
|
+
import { GatewayClient } from "./client.js";
|
|
4
|
+
/** How long catalog evidence stays fresh. Short: splitters can be re-listed. */
|
|
5
|
+
export declare const CATALOG_TTL_SECONDS = 300;
|
|
6
|
+
export interface OutcomeSummary {
|
|
7
|
+
providerAgentId: string;
|
|
8
|
+
outcomeId: string;
|
|
9
|
+
payTo: Address;
|
|
10
|
+
splitterAddress: Address;
|
|
11
|
+
token: Address;
|
|
12
|
+
pricingMode: "fixed" | "dynamic" | string;
|
|
13
|
+
fixedGrossAmount?: string | undefined;
|
|
14
|
+
bindingProfile?: string | undefined;
|
|
15
|
+
providerAudience?: string | undefined;
|
|
16
|
+
absoluteResourceUri?: string | undefined;
|
|
17
|
+
/** Human-facing terms, used to build the approval summary. */
|
|
18
|
+
terms?: Record<string, unknown> | undefined;
|
|
19
|
+
commissionBps?: number | undefined;
|
|
20
|
+
serviceName?: string | undefined;
|
|
21
|
+
skillName?: string | undefined;
|
|
22
|
+
requestSchema?: Record<string, unknown> | undefined;
|
|
23
|
+
}
|
|
24
|
+
export interface ChainManifest {
|
|
25
|
+
chainId: number;
|
|
26
|
+
outcomes: {
|
|
27
|
+
providerAgentId: string;
|
|
28
|
+
outcomeId: string;
|
|
29
|
+
payTo: string;
|
|
30
|
+
splitter?: {
|
|
31
|
+
splitterAddress?: string;
|
|
32
|
+
} | undefined;
|
|
33
|
+
}[];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The catalog reader. One instance per command run, so the TTL cache and the
|
|
37
|
+
* call budget are shared across every check a single purchase performs.
|
|
38
|
+
*/
|
|
39
|
+
export declare class Catalog {
|
|
40
|
+
#private;
|
|
41
|
+
constructor(client: GatewayClient, now?: () => number);
|
|
42
|
+
/** `daski_get_outcome`, cached. This is also the price and terms source. */
|
|
43
|
+
getOutcome(providerAgentId: string, outcomeId: string): Promise<OutcomeSummary>;
|
|
44
|
+
/** `.well-known/daski-chain.json`, cached. The second, independent source. */
|
|
45
|
+
chainManifest(): Promise<ChainManifest>;
|
|
46
|
+
/** The two-source evidence the policy validator consumes. */
|
|
47
|
+
splitterEvidence(providerAgentId: string, outcomeId: string): Promise<SplitterEvidence>;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=catalog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../../src/gateway/catalog.ts"],"names":[],"mappings":"AAWA,OAAO,EAAc,KAAK,OAAO,EAAE,MAAM,MAAM,CAAC;AAChD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAG3D,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,gFAAgF;AAChF,eAAO,MAAM,mBAAmB,MA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