@ampersend_ai/ampersend-sdk 0.0.16 → 0.0.21
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/ampersend/approval.d.ts +8 -8
- package/dist/ampersend/approval.d.ts.map +1 -1
- package/dist/ampersend/approval.js +10 -15
- package/dist/ampersend/approval.js.map +1 -1
- package/dist/ampersend/client.d.ts +4 -9
- package/dist/ampersend/client.d.ts.map +1 -1
- package/dist/ampersend/client.js +25 -21
- package/dist/ampersend/client.js.map +1 -1
- package/dist/ampersend/treasurer.d.ts +14 -79
- package/dist/ampersend/treasurer.d.ts.map +1 -1
- package/dist/ampersend/treasurer.js +34 -102
- package/dist/ampersend/treasurer.js.map +1 -1
- package/dist/ampersend/types.d.ts +356 -338
- package/dist/ampersend/types.d.ts.map +1 -1
- package/dist/ampersend/types.js +120 -150
- package/dist/ampersend/types.js.map +1 -1
- package/dist/ampersend/zod-bridge.d.ts +15 -0
- package/dist/ampersend/zod-bridge.d.ts.map +1 -0
- package/dist/ampersend/zod-bridge.js +29 -0
- package/dist/ampersend/zod-bridge.js.map +1 -0
- package/dist/cli/commands/fetch.d.ts.map +1 -1
- package/dist/cli/commands/fetch.js.map +1 -1
- package/dist/cli/commands/setup.d.ts +4 -0
- package/dist/cli/commands/setup.d.ts.map +1 -1
- package/dist/cli/commands/setup.js +52 -7
- package/dist/cli/commands/setup.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/mcp/client/client.d.ts +0 -3
- package/dist/mcp/client/client.d.ts.map +1 -1
- package/dist/mcp/client/client.js +10 -14
- package/dist/mcp/client/client.js.map +1 -1
- package/dist/mcp/client/factory.d.ts +0 -2
- package/dist/mcp/client/factory.d.ts.map +1 -1
- package/dist/mcp/client/factory.js +0 -3
- package/dist/mcp/client/factory.js.map +1 -1
- package/dist/mcp/client/middleware.d.ts +0 -3
- package/dist/mcp/client/middleware.d.ts.map +1 -1
- package/dist/mcp/client/middleware.js +9 -12
- package/dist/mcp/client/middleware.js.map +1 -1
- package/dist/mcp/client/protocol.d.ts +81 -85
- package/dist/mcp/client/protocol.d.ts.map +1 -1
- package/dist/mcp/client/protocol.js +17 -15
- package/dist/mcp/client/protocol.js.map +1 -1
- package/dist/mcp/client/types.d.ts +6 -19
- package/dist/mcp/client/types.d.ts.map +1 -1
- package/dist/mcp/proxy/cli.d.ts.map +1 -1
- package/dist/mcp/proxy/cli.js +0 -1
- package/dist/mcp/proxy/cli.js.map +1 -1
- package/dist/mcp/proxy/env.d.ts +0 -9
- package/dist/mcp/proxy/env.d.ts.map +1 -1
- package/dist/mcp/proxy/env.js +0 -2
- package/dist/mcp/proxy/env.js.map +1 -1
- package/dist/mcp/proxy/factory.d.ts +0 -2
- package/dist/mcp/proxy/factory.d.ts.map +1 -1
- package/dist/mcp/proxy/factory.js +0 -3
- package/dist/mcp/proxy/factory.js.map +1 -1
- package/dist/mcp/server/fastmcp/middleware.d.ts +9 -29
- package/dist/mcp/server/fastmcp/middleware.d.ts.map +1 -1
- package/dist/mcp/server/fastmcp/middleware.js +10 -42
- package/dist/mcp/server/fastmcp/middleware.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/x402/envelopes.d.ts +62 -0
- package/dist/x402/envelopes.d.ts.map +1 -0
- package/dist/x402/envelopes.js +73 -0
- package/dist/x402/envelopes.js.map +1 -0
- package/dist/x402/http/client.d.ts +37 -0
- package/dist/x402/http/client.d.ts.map +1 -0
- package/dist/x402/http/client.js +159 -0
- package/dist/x402/http/client.js.map +1 -0
- package/dist/x402/http/factory.d.ts +11 -25
- package/dist/x402/http/factory.d.ts.map +1 -1
- package/dist/x402/http/factory.js +11 -22
- package/dist/x402/http/factory.js.map +1 -1
- package/dist/x402/http/index.d.ts +4 -1
- package/dist/x402/http/index.d.ts.map +1 -1
- package/dist/x402/http/index.js +2 -1
- package/dist/x402/http/index.js.map +1 -1
- package/dist/x402/index.d.ts +4 -1
- package/dist/x402/index.d.ts.map +1 -1
- package/dist/x402/index.js +3 -2
- package/dist/x402/index.js.map +1 -1
- package/dist/x402/treasurer.d.ts +22 -47
- package/dist/x402/treasurer.d.ts.map +1 -1
- package/dist/x402/treasurers/naive.d.ts +4 -40
- package/dist/x402/treasurers/naive.d.ts.map +1 -1
- package/dist/x402/treasurers/naive.js +7 -44
- package/dist/x402/treasurers/naive.js.map +1 -1
- package/dist/x402/wallet.d.ts +7 -32
- package/dist/x402/wallet.d.ts.map +1 -1
- package/dist/x402/wallet.js +0 -3
- package/dist/x402/wallet.js.map +1 -1
- package/dist/x402/wallets/account/wallet.d.ts +9 -30
- package/dist/x402/wallets/account/wallet.d.ts.map +1 -1
- package/dist/x402/wallets/account/wallet.js +30 -37
- package/dist/x402/wallets/account/wallet.js.map +1 -1
- package/dist/x402/wallets/index.d.ts +0 -1
- package/dist/x402/wallets/index.d.ts.map +1 -1
- package/dist/x402/wallets/index.js +0 -1
- package/dist/x402/wallets/index.js.map +1 -1
- package/dist/x402/wallets/smart-account/chain.d.ts +4 -0
- package/dist/x402/wallets/smart-account/chain.d.ts.map +1 -0
- package/dist/x402/wallets/smart-account/chain.js +12 -0
- package/dist/x402/wallets/smart-account/chain.js.map +1 -0
- package/dist/x402/wallets/smart-account/cosigned.d.ts +7 -33
- package/dist/x402/wallets/smart-account/cosigned.d.ts.map +1 -1
- package/dist/x402/wallets/smart-account/cosigned.js +28 -51
- package/dist/x402/wallets/smart-account/cosigned.js.map +1 -1
- package/dist/x402/wallets/smart-account/exact.d.ts +6 -20
- package/dist/x402/wallets/smart-account/exact.d.ts.map +1 -1
- package/dist/x402/wallets/smart-account/exact.js +33 -43
- package/dist/x402/wallets/smart-account/exact.js.map +1 -1
- package/dist/x402/wallets/smart-account/wallet.d.ts +6 -39
- package/dist/x402/wallets/smart-account/wallet.d.ts.map +1 -1
- package/dist/x402/wallets/smart-account/wallet.js +9 -36
- package/dist/x402/wallets/smart-account/wallet.js.map +1 -1
- package/package.json +8 -6
- package/dist/x402/http/adapter.d.ts +0 -38
- package/dist/x402/http/adapter.d.ts.map +0 -1
- package/dist/x402/http/adapter.js +0 -199
- package/dist/x402/http/adapter.js.map +0 -1
- package/dist/x402/http/v2-adapter.d.ts +0 -56
- package/dist/x402/http/v2-adapter.d.ts.map +0 -1
- package/dist/x402/http/v2-adapter.js +0 -94
- package/dist/x402/http/v2-adapter.js.map +0 -1
|
@@ -1,59 +1,52 @@
|
|
|
1
|
+
import { ExactEvmScheme, toClientEvmSigner } from "@x402/evm";
|
|
2
|
+
import { ExactEvmSchemeV1 } from "@x402/evm/v1";
|
|
1
3
|
import { privateKeyToAccount } from "viem/accounts";
|
|
2
|
-
import {
|
|
4
|
+
import { acceptedOf, buildAuthorization } from "../../envelopes.js";
|
|
3
5
|
import { WalletError } from "../../wallet.js";
|
|
4
6
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* Supports the "exact" payment scheme.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```typescript
|
|
12
|
-
* import { privateKeyToAccount } from "viem/accounts"
|
|
13
|
-
*
|
|
14
|
-
* // From viem Account
|
|
15
|
-
* const account = privateKeyToAccount("0x...")
|
|
16
|
-
* const wallet = new AccountWallet(account)
|
|
17
|
-
*
|
|
18
|
-
* // From private key directly
|
|
19
|
-
* const wallet = AccountWallet.fromPrivateKey("0x...")
|
|
20
|
-
* ```
|
|
7
|
+
* EOA wallet for x402 `exact` on EVM. A `LocalAccount` is sufficient for
|
|
8
|
+
* EIP-3009 and base Permit2; EIP-2612 permit enrichment is skipped because it
|
|
9
|
+
* needs `readContract`, which `LocalAccount` lacks.
|
|
21
10
|
*/
|
|
22
11
|
export class AccountWallet {
|
|
23
12
|
account;
|
|
13
|
+
signer;
|
|
14
|
+
schemeV1;
|
|
15
|
+
schemeV2;
|
|
24
16
|
constructor(account) {
|
|
25
17
|
this.account = account;
|
|
18
|
+
this.signer = toClientEvmSigner({
|
|
19
|
+
address: account.address,
|
|
20
|
+
signTypedData: (msg) => account.signTypedData(msg),
|
|
21
|
+
});
|
|
22
|
+
this.schemeV1 = new ExactEvmSchemeV1(this.signer);
|
|
23
|
+
this.schemeV2 = new ExactEvmScheme(this.signer);
|
|
26
24
|
}
|
|
27
|
-
/**
|
|
28
|
-
* Creates an AccountWallet from a private key
|
|
29
|
-
*/
|
|
30
25
|
static fromPrivateKey(privateKey) {
|
|
31
26
|
return new AccountWallet(privateKeyToAccount(privateKey));
|
|
32
27
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
*/
|
|
38
|
-
async createPayment(requirements, _serverAuthorization) {
|
|
39
|
-
if (requirements.scheme !== "exact") {
|
|
40
|
-
throw new WalletError(`Unsupported payment scheme: ${requirements.scheme}. AccountWallet only supports "exact".`);
|
|
28
|
+
async createPayment(instruction, serverAuthorization) {
|
|
29
|
+
if (serverAuthorization) {
|
|
30
|
+
throw new WalletError("AccountWallet received a co-signed authorization from the server, but EOA accounts " +
|
|
31
|
+
"cannot produce ERC-1271 co-signed payments. Use SmartAccountWallet for co-signed agent keys.");
|
|
41
32
|
}
|
|
33
|
+
const accepted = acceptedOf(instruction);
|
|
34
|
+
if (accepted.scheme !== "exact") {
|
|
35
|
+
throw new WalletError(`Unsupported payment scheme: ${accepted.scheme}. AccountWallet only supports "exact".`);
|
|
36
|
+
}
|
|
37
|
+
// Zod-inferred shape → upstream v2-surface shape. Nominal mismatch only;
|
|
38
|
+
// each scheme re-narrows to the version it needs at runtime.
|
|
39
|
+
const requirements = accepted;
|
|
42
40
|
try {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const payment = JSON.parse(decoded);
|
|
48
|
-
return payment;
|
|
41
|
+
const result = instruction.protocol === "x402-v1"
|
|
42
|
+
? await this.schemeV1.createPaymentPayload(1, requirements)
|
|
43
|
+
: await this.schemeV2.createPaymentPayload(2, requirements, instruction.request.extensions ? { extensions: instruction.request.extensions } : undefined);
|
|
44
|
+
return buildAuthorization(instruction, result.payload);
|
|
49
45
|
}
|
|
50
46
|
catch (error) {
|
|
51
47
|
throw new WalletError(`Failed to create payment: ${error instanceof Error ? error.message : String(error)}`, error instanceof Error ? error : undefined);
|
|
52
48
|
}
|
|
53
49
|
}
|
|
54
|
-
/**
|
|
55
|
-
* Returns the account address
|
|
56
|
-
*/
|
|
57
50
|
get address() {
|
|
58
51
|
return this.account.address;
|
|
59
52
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../../../src/x402/wallets/account/wallet.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../../../src/x402/wallets/account/wallet.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAwB,MAAM,WAAW,CAAA;AACnF,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAE/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AAEnD,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAsD,MAAM,oBAAoB,CAAA;AAEvH,OAAO,EAAE,WAAW,EAAmB,MAAM,iBAAiB,CAAA;AAE9D;;;;GAIG;AACH,MAAM,OAAO,aAAa;IAChB,OAAO,CAAc;IACrB,MAAM,CAAiB;IACvB,QAAQ,CAAkB;IAC1B,QAAQ,CAAgB;IAEhC,YAAY,OAAqB;QAC/B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,MAAM,GAAG,iBAAiB,CAAC;YAC9B,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,aAAa,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,aAAa,C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O,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,WAAW,CACnB,6BAA6B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EACrF,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAC3C,CAAA;QACH,CAAC;IACH,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAA;IAC7B,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/x402/wallets/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAA;AAExC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAI9C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,kBAAkB,EAAE,KAAK,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAEvF;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,KAAK,CAAA;IACX,UAAU,EAAE,GAAG,CAAA;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,eAAe,CAAA;IACrB,mBAAmB,EAAE,OAAO,CAAA;IAC5B,oBAAoB,EAAE,GAAG,CAAA;IACzB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/x402/wallets/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAA;AAExC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAI9C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,kBAAkB,EAAE,KAAK,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAEvF;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,KAAK,CAAA;IACX,UAAU,EAAE,GAAG,CAAA;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,eAAe,CAAA;IACrB,mBAAmB,EAAE,OAAO,CAAA;IAC5B,oBAAoB,EAAE,GAAG,CAAA;IACzB,gBAAgB,EAAE,OAAO,CAAA;IACzB,wBAAwB,CAAC,EAAE,OAAO,CAAA;CACnC;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,eAAe,GAAG,wBAAwB,CAAA;AAErE;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,YAAY,GAAG,UAAU,CAWvE"}
|
|
@@ -16,7 +16,6 @@ export function createWalletFromConfig(config) {
|
|
|
16
16
|
return new SmartAccountWallet({
|
|
17
17
|
smartAccountAddress: config.smartAccountAddress,
|
|
18
18
|
sessionKeyPrivateKey: config.sessionKeyPrivateKey,
|
|
19
|
-
chainId: config.chainId,
|
|
20
19
|
validatorAddress: config.validatorAddress,
|
|
21
20
|
...(config.coSignerValidatorAddress != null && { coSignerValidatorAddress: config.coSignerValidatorAddress }),
|
|
22
21
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/x402/wallets/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAE9D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,kBAAkB,EAA2B,MAAM,2BAA2B,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/x402/wallets/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAE9D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,kBAAkB,EAA2B,MAAM,2BAA2B,CAAA;AA0BvF;;;;;;GAMG;AACH,MAAM,UAAU,sBAAsB,CAAC,MAAoB;IACzD,IAAI,MAAM,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;QAC1B,OAAO,aAAa,CAAC,cAAc,CAAC,MAAM,CAAC,UAAU,CAAC,CAAA;IACxD,CAAC;IAED,OAAO,IAAI,kBAAkB,CAAC;QAC5B,mBAAmB,EAAE,MAAM,CAAC,mBAAmB;QAC/C,oBAAoB,EAAE,MAAM,CAAC,oBAAoB;QACjD,gBAAgB,EAAE,MAAM,CAAC,gBAAgB;QACzC,GAAG,CAAC,MAAM,CAAC,wBAAwB,IAAI,IAAI,IAAI,EAAE,wBAAwB,EAAE,MAAM,CAAC,wBAAwB,EAAE,CAAC;KAC9G,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type PaymentInstruction } from "../../envelopes.ts";
|
|
2
|
+
/** v1 looks up the network name; v2 parses `eip155:N`. Returns `null` for unsupported networks. */
|
|
3
|
+
export declare function chainIdOf(instruction: PaymentInstruction): number | null;
|
|
4
|
+
//# sourceMappingURL=chain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chain.d.ts","sourceRoot":"","sources":["../../../../src/x402/wallets/smart-account/chain.ts"],"names":[],"mappings":"AAEA,OAAO,EAAc,KAAK,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAExE,mGAAmG;AACnG,wBAAgB,SAAS,CAAC,WAAW,EAAE,kBAAkB,GAAG,MAAM,GAAG,IAAI,CAOxE"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { EVM_NETWORK_CHAIN_ID_MAP } from "@x402/evm/v1";
|
|
2
|
+
import { acceptedOf } from "../../envelopes.js";
|
|
3
|
+
/** v1 looks up the network name; v2 parses `eip155:N`. Returns `null` for unsupported networks. */
|
|
4
|
+
export function chainIdOf(instruction) {
|
|
5
|
+
const network = acceptedOf(instruction).network;
|
|
6
|
+
if (instruction.protocol === "x402-v1") {
|
|
7
|
+
return EVM_NETWORK_CHAIN_ID_MAP[network] ?? null;
|
|
8
|
+
}
|
|
9
|
+
const match = /^eip155:(\d+)$/.exec(network);
|
|
10
|
+
return match ? Number(match[1]) : null;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=chain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chain.js","sourceRoot":"","sources":["../../../../src/x402/wallets/smart-account/chain.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAA;AAEvD,OAAO,EAAE,UAAU,EAA2B,MAAM,oBAAoB,CAAA;AAExE,mGAAmG;AACnG,MAAM,UAAU,SAAS,CAAC,WAA+B;IACvD,MAAM,OAAO,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC,OAAO,CAAA;IAC/C,IAAI,WAAW,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;QACvC,OAAQ,wBAA6D,CAAC,OAAO,CAAC,IAAI,IAAI,CAAA;IACxF,CAAC;IACD,MAAM,KAAK,GAAG,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAC5C,OAAO,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;AACxC,CAAC"}
|
|
@@ -1,46 +1,20 @@
|
|
|
1
1
|
import { type Address, type Hex, type TypedDataDefinition } from "viem";
|
|
2
|
-
import type
|
|
2
|
+
import { type PaymentAuthorization, type PaymentInstruction } from "../../envelopes.ts";
|
|
3
3
|
import type { ServerAuthorizationData } from "../../types.ts";
|
|
4
|
-
/**
|
|
5
|
-
* Configuration for creating a co-signed payment
|
|
6
|
-
*/
|
|
7
4
|
export interface CoSignedPaymentConfig {
|
|
8
|
-
/** Smart account address (payment sender) */
|
|
9
5
|
smartAccountAddress: Address;
|
|
10
|
-
/** Session key private key for signing */
|
|
11
6
|
sessionKeyPrivateKey: Hex;
|
|
12
|
-
/** Chain ID for the blockchain network */
|
|
13
|
-
chainId: number;
|
|
14
|
-
/** CoSignerValidator address */
|
|
15
7
|
coSignerValidatorAddress: Address;
|
|
16
8
|
}
|
|
17
9
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* Combines agent signature + server signature according to CoSignerValidator format:
|
|
21
|
-
* 1. Sign typed data with agent key (raw ECDSA)
|
|
22
|
-
* 2. Combine: abi.encode(agentSig, serverSig)
|
|
23
|
-
* 3. Wrap for ERC-1271: encodePacked(validatorAddress, combined)
|
|
24
|
-
*
|
|
25
|
-
* @param agentPrivateKey - Agent's session key private key
|
|
26
|
-
* @param typedDataParams - EIP-712 typed data to sign
|
|
27
|
-
* @param serverSignature - Server's ECDSA signature (65 bytes as hex)
|
|
28
|
-
* @param coSignerValidatorAddress - CoSignerValidator contract address
|
|
29
|
-
* @returns ERC-1271 formatted signature
|
|
10
|
+
* CoSignerValidator ERC-1271 signature: agent signs → `abi.encode(agentSig, serverSig)`
|
|
11
|
+
* → `encodePacked(validator, combined)`.
|
|
30
12
|
*/
|
|
31
13
|
export declare function encodeCoSignedERC1271Signature(agentPrivateKey: Hex, typedDataParams: TypedDataDefinition, serverSignature: Hex, coSignerValidatorAddress: Address): Promise<Hex>;
|
|
32
14
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* authorization data and co-signature. The agent key adds its signature and
|
|
37
|
-
* combines them for ERC-1271 validation via CoSignerValidator.
|
|
38
|
-
*
|
|
39
|
-
* @param requirements - Payment requirements from the x402 server
|
|
40
|
-
* @param config - Configuration for the smart account wallet
|
|
41
|
-
* @param serverAuthorization - Server-provided authorization data and co-signature
|
|
42
|
-
* @returns Payment payload ready to send to x402 server
|
|
43
|
-
* @throws Error if requirements are invalid or signing fails
|
|
15
|
+
* Sign a co-signed `exact` instruction. Server supplies ERC-3009
|
|
16
|
+
* authorization data + its signature; agent adds its own and the pair is
|
|
17
|
+
* validated via CoSignerValidator under ERC-1271.
|
|
44
18
|
*/
|
|
45
|
-
export declare function createCoSignedPayment(
|
|
19
|
+
export declare function createCoSignedPayment(instruction: PaymentInstruction, config: CoSignedPaymentConfig, serverAuthorization: ServerAuthorizationData): Promise<PaymentAuthorization>;
|
|
46
20
|
//# sourceMappingURL=cosigned.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cosigned.d.ts","sourceRoot":"","sources":["../../../../src/x402/wallets/smart-account/cosigned.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqC,KAAK,OAAO,EAAE,KAAK,GAAG,EAAE,KAAK,mBAAmB,EAAE,MAAM,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"cosigned.d.ts","sourceRoot":"","sources":["../../../../src/x402/wallets/smart-account/cosigned.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqC,KAAK,OAAO,EAAE,KAAK,GAAG,EAAE,KAAK,mBAAmB,EAAE,MAAM,MAAM,CAAA;AAI1G,OAAO,EAAkC,KAAK,oBAAoB,EAAE,KAAK,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AACvH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAA;AAG7D,MAAM,WAAW,qBAAqB;IACpC,mBAAmB,EAAE,OAAO,CAAA;IAC5B,oBAAoB,EAAE,GAAG,CAAA;IACzB,wBAAwB,EAAE,OAAO,CAAA;CAClC;AAED;;;GAGG;AACH,wBAAsB,8BAA8B,CAClD,eAAe,EAAE,GAAG,EACpB,eAAe,EAAE,mBAAmB,EACpC,eAAe,EAAE,GAAG,EACpB,wBAAwB,EAAE,OAAO,GAChC,OAAO,CAAC,GAAG,CAAC,CAUd;AAED;;;;GAIG;AACH,wBAAsB,qBAAqB,CACzC,WAAW,EAAE,kBAAkB,EAC/B,MAAM,EAAE,qBAAqB,EAC7B,mBAAmB,EAAE,uBAAuB,GAC3C,OAAO,CAAC,oBAAoB,CAAC,CAyD/B"}
|
|
@@ -1,57 +1,41 @@
|
|
|
1
1
|
import { encodeAbiParameters, encodePacked } from "viem";
|
|
2
2
|
import { privateKeyToAccount } from "viem/accounts";
|
|
3
3
|
import { TRANSFER_WITH_AUTHORIZATION_TYPE } from "../../../smart-account/eip712-types.js";
|
|
4
|
+
import { acceptedOf, buildAuthorization } from "../../envelopes.js";
|
|
5
|
+
import { chainIdOf } from "./chain.js";
|
|
4
6
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* Combines agent signature + server signature according to CoSignerValidator format:
|
|
8
|
-
* 1. Sign typed data with agent key (raw ECDSA)
|
|
9
|
-
* 2. Combine: abi.encode(agentSig, serverSig)
|
|
10
|
-
* 3. Wrap for ERC-1271: encodePacked(validatorAddress, combined)
|
|
11
|
-
*
|
|
12
|
-
* @param agentPrivateKey - Agent's session key private key
|
|
13
|
-
* @param typedDataParams - EIP-712 typed data to sign
|
|
14
|
-
* @param serverSignature - Server's ECDSA signature (65 bytes as hex)
|
|
15
|
-
* @param coSignerValidatorAddress - CoSignerValidator contract address
|
|
16
|
-
* @returns ERC-1271 formatted signature
|
|
7
|
+
* CoSignerValidator ERC-1271 signature: agent signs → `abi.encode(agentSig, serverSig)`
|
|
8
|
+
* → `encodePacked(validator, combined)`.
|
|
17
9
|
*/
|
|
18
10
|
export async function encodeCoSignedERC1271Signature(agentPrivateKey, typedDataParams, serverSignature, coSignerValidatorAddress) {
|
|
19
|
-
// 1. Sign with agent key
|
|
20
11
|
const agentAccount = privateKeyToAccount(agentPrivateKey);
|
|
21
12
|
const agentSignature = await agentAccount.signTypedData(typedDataParams);
|
|
22
|
-
// 2. Combine signatures: abi.encode(bytes agentSig, bytes serverSig)
|
|
23
13
|
const combinedSignature = encodeAbiParameters([{ type: "bytes" }, { type: "bytes" }], [agentSignature, serverSignature]);
|
|
24
|
-
// 3. Encode for ERC-1271: encodePacked(address validator, bytes signature)
|
|
25
14
|
return encodePacked(["address", "bytes"], [coSignerValidatorAddress, combinedSignature]);
|
|
26
15
|
}
|
|
27
16
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* authorization data and co-signature. The agent key adds its signature and
|
|
32
|
-
* combines them for ERC-1271 validation via CoSignerValidator.
|
|
33
|
-
*
|
|
34
|
-
* @param requirements - Payment requirements from the x402 server
|
|
35
|
-
* @param config - Configuration for the smart account wallet
|
|
36
|
-
* @param serverAuthorization - Server-provided authorization data and co-signature
|
|
37
|
-
* @returns Payment payload ready to send to x402 server
|
|
38
|
-
* @throws Error if requirements are invalid or signing fails
|
|
17
|
+
* Sign a co-signed `exact` instruction. Server supplies ERC-3009
|
|
18
|
+
* authorization data + its signature; agent adds its own and the pair is
|
|
19
|
+
* validated via CoSignerValidator under ERC-1271.
|
|
39
20
|
*/
|
|
40
|
-
export async function createCoSignedPayment(
|
|
21
|
+
export async function createCoSignedPayment(instruction, config, serverAuthorization) {
|
|
41
22
|
const { authorizationData, serverSignature } = serverAuthorization;
|
|
42
|
-
|
|
43
|
-
const domainName =
|
|
44
|
-
const domainVersion =
|
|
23
|
+
const accepted = acceptedOf(instruction);
|
|
24
|
+
const domainName = accepted.extra?.name;
|
|
25
|
+
const domainVersion = accepted.extra?.version;
|
|
45
26
|
if (!domainName || !domainVersion) {
|
|
46
|
-
throw new Error("
|
|
27
|
+
throw new Error("accepted.extra must contain 'name' and 'version' for EIP-712 domain");
|
|
28
|
+
}
|
|
29
|
+
const chainId = chainIdOf(instruction);
|
|
30
|
+
if (chainId === null) {
|
|
31
|
+
throw new Error(`Unsupported network "${accepted.network}" — use a known v1 name or CAIP-2 "eip155:N".`);
|
|
47
32
|
}
|
|
48
|
-
// Construct EIP-712 typed data from server-provided authorization data
|
|
49
33
|
const typedData = {
|
|
50
34
|
domain: {
|
|
51
35
|
name: domainName,
|
|
52
36
|
version: domainVersion,
|
|
53
|
-
chainId
|
|
54
|
-
verifyingContract:
|
|
37
|
+
chainId,
|
|
38
|
+
verifyingContract: accepted.asset,
|
|
55
39
|
},
|
|
56
40
|
types: {
|
|
57
41
|
TransferWithAuthorization: TRANSFER_WITH_AUTHORIZATION_TYPE,
|
|
@@ -66,25 +50,18 @@ export async function createCoSignedPayment(requirements, config, serverAuthoriz
|
|
|
66
50
|
nonce: authorizationData.nonce,
|
|
67
51
|
},
|
|
68
52
|
};
|
|
69
|
-
// Encode co-signed signature
|
|
70
53
|
const signature = await encodeCoSignedERC1271Signature(config.sessionKeyPrivateKey, typedData, serverSignature, config.coSignerValidatorAddress);
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
to: authorizationData.to,
|
|
81
|
-
value: authorizationData.value,
|
|
82
|
-
validAfter: authorizationData.validAfter,
|
|
83
|
-
validBefore: authorizationData.validBefore,
|
|
84
|
-
nonce: authorizationData.nonce,
|
|
85
|
-
},
|
|
54
|
+
const signedPayload = {
|
|
55
|
+
signature: signature,
|
|
56
|
+
authorization: {
|
|
57
|
+
from: authorizationData.from,
|
|
58
|
+
to: authorizationData.to,
|
|
59
|
+
value: authorizationData.value,
|
|
60
|
+
validAfter: authorizationData.validAfter,
|
|
61
|
+
validBefore: authorizationData.validBefore,
|
|
62
|
+
nonce: authorizationData.nonce,
|
|
86
63
|
},
|
|
87
64
|
};
|
|
88
|
-
return
|
|
65
|
+
return buildAuthorization(instruction, signedPayload);
|
|
89
66
|
}
|
|
90
67
|
//# sourceMappingURL=cosigned.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cosigned.js","sourceRoot":"","sources":["../../../../src/x402/wallets/smart-account/cosigned.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAoD,MAAM,MAAM,CAAA;AAC1G,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"cosigned.js","sourceRoot":"","sources":["../../../../src/x402/wallets/smart-account/cosigned.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAoD,MAAM,MAAM,CAAA;AAC1G,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AAEnD,OAAO,EAAE,gCAAgC,EAAE,MAAM,wCAAwC,CAAA;AACzF,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAsD,MAAM,oBAAoB,CAAA;AAEvH,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAQtC;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,8BAA8B,CAClD,eAAoB,EACpB,eAAoC,EACpC,eAAoB,EACpB,wBAAiC;IAEjC,MAAM,YAAY,GAAG,mBAAmB,CAAC,eAAe,CAAC,CAAA;IACzD,MAAM,cAAc,GAAG,MAAM,YAAY,CAAC,aAAa,CAAC,eAAe,CAAC,CAAA;IAExE,MAAM,iBAAiB,GAAG,mBAAmB,CAC3C,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,EACtC,CAAC,cAAc,EAAE,eAAe,CAAC,CAClC,CAAA;IAED,OAAO,YAAY,CAAC,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE,CAAC,wBAAwB,EAAE,iBAAiB,CAAC,CAAC,CAAA;AAC1F,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,WAA+B,EAC/B,MAA6B,EAC7B,mBAA4C;IAE5C,MAAM,EAAE,iBAAiB,EAAE,eAAe,EAAE,GAAG,mBAAmB,CAAA;IAClE,MAAM,QAAQ,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CAAC,IAAI;YAC5B,EAAE,EAAE,iBAAiB,CAAC,EAAE;YACxB,KAAK,EAAE,iBAAiB,CAAC,KAAK;YAC9B,UAAU,EAAE,iBAAiB,CAAC,UAAU;YACxC,WAAW,EAAE,iBAAiB,CAAC,WAAW;YAC1C,KAAK,EAAE,iBAAiB,CAAC,KAAK;SAC/B;KACF,CAAA;IAED,OAAO,kBAAkB,CAAC,WAAW,EAAE,aAAa,CAAC,CAAA;AACvD,CAAC"}
|
|
@@ -1,29 +1,15 @@
|
|
|
1
1
|
import { type Address, type Hex } from "viem";
|
|
2
|
-
import type
|
|
3
|
-
/**
|
|
4
|
-
* Configuration for creating an exact payment with ERC-3009
|
|
5
|
-
*/
|
|
2
|
+
import { type PaymentAuthorization, type PaymentInstruction } from "../../envelopes.ts";
|
|
6
3
|
export interface ExactPaymentConfig {
|
|
7
|
-
/** Smart account address (payment sender) */
|
|
8
4
|
smartAccountAddress: Address;
|
|
9
|
-
/** Session key private key for signing */
|
|
10
5
|
sessionKeyPrivateKey: Hex;
|
|
11
|
-
/**
|
|
12
|
-
chainId: number;
|
|
13
|
-
/** OwnableValidator address for ERC-1271 validation */
|
|
6
|
+
/** OwnableValidator address used for ERC-1271 validation. */
|
|
14
7
|
validatorAddress: Address;
|
|
15
8
|
}
|
|
16
9
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* (ERC-3009) to create signed payment authorizations. The signature is created using ERC-1271
|
|
21
|
-
* from a smart account via the OwnableValidator module.
|
|
22
|
-
*
|
|
23
|
-
* @param requirements - Payment requirements from the x402 server
|
|
24
|
-
* @param config - Configuration for the smart account wallet
|
|
25
|
-
* @returns Payment payload ready to send to x402 server
|
|
26
|
-
* @throws Error if payment requirements are invalid or signing fails
|
|
10
|
+
* Sign an `exact` instruction: ERC-3009 `transferWithAuthorization` via
|
|
11
|
+
* ERC-1271 with OwnableValidator. {@link buildAuthorization} packages the
|
|
12
|
+
* signed body for v1 or v2.
|
|
27
13
|
*/
|
|
28
|
-
export declare function createExactPayment(
|
|
14
|
+
export declare function createExactPayment(instruction: PaymentInstruction, config: ExactPaymentConfig): Promise<PaymentAuthorization>;
|
|
29
15
|
//# sourceMappingURL=exact.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exact.d.ts","sourceRoot":"","sources":["../../../../src/x402/wallets/smart-account/exact.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"exact.d.ts","sourceRoot":"","sources":["../../../../src/x402/wallets/smart-account/exact.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,MAAM,CAAA;AAGpD,OAAO,EAIL,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACxB,MAAM,oBAAoB,CAAA;AAa3B,MAAM,WAAW,kBAAkB;IACjC,mBAAmB,EAAE,OAAO,CAAA;IAC5B,oBAAoB,EAAE,GAAG,CAAA;IACzB,6DAA6D;IAC7D,gBAAgB,EAAE,OAAO,CAAA;CAC1B;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,CACtC,WAAW,EAAE,kBAAkB,EAC/B,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,oBAAoB,CAAC,CAuD/B"}
|
|
@@ -1,67 +1,57 @@
|
|
|
1
1
|
import { toHex } from "viem";
|
|
2
2
|
import { signERC3009Authorization } from "../../../smart-account/index.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*/
|
|
3
|
+
import { acceptedOf, amountOf, buildAuthorization, } from "../../envelopes.js";
|
|
4
|
+
import { chainIdOf } from "./chain.js";
|
|
6
5
|
function createNonce() {
|
|
7
6
|
const cryptoObj = typeof globalThis.crypto !== "undefined" && typeof globalThis.crypto.getRandomValues === "function"
|
|
8
7
|
? globalThis.crypto
|
|
9
|
-
: // Dynamic require
|
|
8
|
+
: // Dynamic require for node.js compatibility.
|
|
10
9
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
11
10
|
require("crypto").webcrypto;
|
|
12
11
|
return toHex(cryptoObj.getRandomValues(new Uint8Array(32)));
|
|
13
12
|
}
|
|
14
13
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* (ERC-3009) to create signed payment authorizations. The signature is created using ERC-1271
|
|
19
|
-
* from a smart account via the OwnableValidator module.
|
|
20
|
-
*
|
|
21
|
-
* @param requirements - Payment requirements from the x402 server
|
|
22
|
-
* @param config - Configuration for the smart account wallet
|
|
23
|
-
* @returns Payment payload ready to send to x402 server
|
|
24
|
-
* @throws Error if payment requirements are invalid or signing fails
|
|
14
|
+
* Sign an `exact` instruction: ERC-3009 `transferWithAuthorization` via
|
|
15
|
+
* ERC-1271 with OwnableValidator. {@link buildAuthorization} packages the
|
|
16
|
+
* signed body for v1 or v2.
|
|
25
17
|
*/
|
|
26
|
-
export async function createExactPayment(
|
|
27
|
-
|
|
18
|
+
export async function createExactPayment(instruction, config) {
|
|
19
|
+
const accepted = acceptedOf(instruction);
|
|
20
|
+
const payTo = accepted.payTo;
|
|
21
|
+
const asset = accepted.asset;
|
|
28
22
|
const nonce = createNonce();
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
|
|
23
|
+
const now = Math.floor(Date.now() / 1000);
|
|
24
|
+
const validAfter = BigInt(now - 600); // 10 minutes of clock-skew tolerance
|
|
25
|
+
const validBefore = BigInt(now + accepted.maxTimeoutSeconds);
|
|
32
26
|
const authData = {
|
|
33
27
|
from: config.smartAccountAddress,
|
|
34
|
-
to:
|
|
35
|
-
value: BigInt(
|
|
28
|
+
to: payTo,
|
|
29
|
+
value: BigInt(amountOf(instruction)),
|
|
36
30
|
validAfter,
|
|
37
31
|
validBefore,
|
|
38
32
|
nonce,
|
|
39
33
|
};
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
const domainVersion = requirements.extra?.version;
|
|
34
|
+
const domainName = accepted.extra?.name;
|
|
35
|
+
const domainVersion = accepted.extra?.version;
|
|
43
36
|
if (!domainName || !domainVersion) {
|
|
44
|
-
throw new Error("
|
|
37
|
+
throw new Error("accepted.extra must contain 'name' and 'version' for EIP-712 domain");
|
|
38
|
+
}
|
|
39
|
+
const chainId = chainIdOf(instruction);
|
|
40
|
+
if (chainId === null) {
|
|
41
|
+
throw new Error(`Unsupported network "${accepted.network}" — use a known v1 name or CAIP-2 "eip155:N".`);
|
|
45
42
|
}
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
from: config.smartAccountAddress,
|
|
57
|
-
to: requirements.payTo,
|
|
58
|
-
value: requirements.maxAmountRequired,
|
|
59
|
-
validAfter: validAfter.toString(),
|
|
60
|
-
validBefore: validBefore.toString(),
|
|
61
|
-
nonce: nonce,
|
|
62
|
-
},
|
|
43
|
+
const signature = await signERC3009Authorization(config.sessionKeyPrivateKey, config.smartAccountAddress, authData, asset, chainId, config.validatorAddress, domainName, domainVersion);
|
|
44
|
+
const signedPayload = {
|
|
45
|
+
signature: signature,
|
|
46
|
+
authorization: {
|
|
47
|
+
from: config.smartAccountAddress,
|
|
48
|
+
to: payTo,
|
|
49
|
+
value: amountOf(instruction),
|
|
50
|
+
validAfter: validAfter.toString(),
|
|
51
|
+
validBefore: validBefore.toString(),
|
|
52
|
+
nonce: nonce,
|
|
63
53
|
},
|
|
64
54
|
};
|
|
65
|
-
return
|
|
55
|
+
return buildAuthorization(instruction, signedPayload);
|
|
66
56
|
}
|
|
67
57
|
//# sourceMappingURL=exact.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exact.js","sourceRoot":"","sources":["../../../../src/x402/wallets/smart-account/exact.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK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
|
|
1
1
|
import { type Address, type Hex } from "viem";
|
|
2
|
-
import type
|
|
2
|
+
import { type PaymentAuthorization, type PaymentInstruction } from "../../envelopes.ts";
|
|
3
3
|
import type { ServerAuthorizationData } from "../../types.ts";
|
|
4
4
|
import { type X402Wallet } from "../../wallet.ts";
|
|
5
|
-
/**
|
|
6
|
-
* Configuration for SmartAccountWallet
|
|
7
|
-
*/
|
|
8
5
|
export interface SmartAccountConfig {
|
|
9
|
-
/** Smart account address */
|
|
10
6
|
smartAccountAddress: Address;
|
|
11
|
-
/** Session key private key for signing */
|
|
12
7
|
sessionKeyPrivateKey: Hex;
|
|
13
|
-
/**
|
|
14
|
-
chainId: number;
|
|
15
|
-
/** OwnableValidator address (defaults to standard OwnableValidator) */
|
|
8
|
+
/** OwnableValidator address. Defaults to the standard OwnableValidator. */
|
|
16
9
|
validatorAddress?: Address;
|
|
17
|
-
/** CoSignerValidator address
|
|
10
|
+
/** CoSignerValidator address. Defaults to the standard CoSignerValidator. */
|
|
18
11
|
coSignerValidatorAddress?: Address;
|
|
19
12
|
}
|
|
20
13
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* Creates payment payloads signed by a smart account using ERC-1271 standard.
|
|
24
|
-
* Supports Safe accounts with OwnableValidator module.
|
|
25
|
-
* Only supports the "exact" payment scheme with ERC-3009 (USDC) authorizations.
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* ```typescript
|
|
29
|
-
* const wallet = new SmartAccountWallet({
|
|
30
|
-
* smartAccountAddress: "0x...", // Smart account address
|
|
31
|
-
* sessionKeyPrivateKey: "0x...", // Session key
|
|
32
|
-
* chainId: 84532, // Base Sepolia
|
|
33
|
-
* validatorAddress: "0x..." // OwnableValidator (optional, defaults to standard validator)
|
|
34
|
-
* })
|
|
35
|
-
*
|
|
36
|
-
* const payment = await wallet.createPayment(requirements)
|
|
37
|
-
* ```
|
|
14
|
+
* Smart account wallet using ERC-1271. Supports Safe accounts with the
|
|
15
|
+
* OwnableValidator module and only the `exact` scheme (ERC-3009 / USDC).
|
|
38
16
|
*/
|
|
39
17
|
export declare class SmartAccountWallet implements X402Wallet {
|
|
40
18
|
private readonly config;
|
|
41
19
|
constructor(config: SmartAccountConfig);
|
|
42
|
-
|
|
43
|
-
* Creates a payment payload from requirements.
|
|
44
|
-
* Only supports "exact" payment scheme with ERC-3009 authorizations.
|
|
45
|
-
*
|
|
46
|
-
* @param requirements Payment requirements from x402
|
|
47
|
-
* @param serverAuthorization Optional server co-signature data for co-signed keys
|
|
48
|
-
* @returns Payment payload ready to submit
|
|
49
|
-
*/
|
|
50
|
-
createPayment(requirements: PaymentRequirements, serverAuthorization?: ServerAuthorizationData): Promise<PaymentPayload>;
|
|
51
|
-
/**
|
|
52
|
-
* Returns the smart account address
|
|
53
|
-
*/
|
|
20
|
+
createPayment(instruction: PaymentInstruction, serverAuthorization?: ServerAuthorizationData): Promise<PaymentAuthorization>;
|
|
54
21
|
get address(): Address;
|
|
55
22
|
}
|
|
56
23
|
//# sourceMappingURL=wallet.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../../../src/x402/wallets/smart-account/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../../../src/x402/wallets/smart-account/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,MAAM,CAAA;AAG7C,OAAO,EAAc,KAAK,oBAAoB,EAAE,KAAK,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AACnG,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAA;AAC7D,OAAO,EAAe,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAI9D,MAAM,WAAW,kBAAkB;IACjC,mBAAmB,EAAE,OAAO,CAAA;IAC5B,oBAAoB,EAAE,GAAG,CAAA;IACzB,2EAA2E;IAC3E,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,6EAA6E;IAC7E,wBAAwB,CAAC,EAAE,OAAO,CAAA;CACnC;AAED;;;GAGG;AACH,qBAAa,kBAAmB,YAAW,UAAU;IACnD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuF;gBAElG,MAAM,EAAE,kBAAkB;IAQhC,aAAa,CACjB,WAAW,EAAE,kBAAkB,EAC/B,mBAAmB,CAAC,EAAE,uBAAuB,GAC5C,OAAO,CAAC,oBAAoB,CAAC;IAmBhC,IAAI,OAAO,IAAI,OAAO,CAErB;CACF"}
|