@ampersend_ai/ampersend-sdk 0.0.22 → 0.0.25
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/agent-client.d.ts +81 -0
- package/dist/ampersend/agent-client.d.ts.map +1 -0
- package/dist/ampersend/agent-client.js +104 -0
- package/dist/ampersend/agent-client.js.map +1 -0
- package/dist/ampersend/agent.d.ts +119 -0
- package/dist/ampersend/agent.d.ts.map +1 -0
- package/dist/ampersend/agent.js +99 -0
- package/dist/ampersend/agent.js.map +1 -0
- package/dist/ampersend/client.d.ts +32 -8
- package/dist/ampersend/client.d.ts.map +1 -1
- package/dist/ampersend/client.js +81 -3
- package/dist/ampersend/client.js.map +1 -1
- package/dist/ampersend/curated-agent.d.ts +3 -3
- package/dist/ampersend/curated-agent.d.ts.map +1 -1
- package/dist/ampersend/curated-agent.js +1 -1
- package/dist/ampersend/curated-agent.js.map +1 -1
- package/dist/ampersend/index.d.ts +2 -0
- package/dist/ampersend/index.d.ts.map +1 -1
- package/dist/ampersend/index.js +4 -0
- package/dist/ampersend/index.js.map +1 -1
- package/dist/ampersend/marketplace.d.ts +20 -14
- package/dist/ampersend/marketplace.d.ts.map +1 -1
- package/dist/ampersend/marketplace.js +23 -49
- package/dist/ampersend/marketplace.js.map +1 -1
- package/dist/ampersend/treasurer.d.ts +4 -0
- package/dist/ampersend/treasurer.d.ts.map +1 -1
- package/dist/ampersend/treasurer.js +2 -2
- package/dist/ampersend/treasurer.js.map +1 -1
- package/dist/ampersend/types.d.ts +35 -6
- package/dist/ampersend/types.d.ts.map +1 -1
- package/dist/ampersend/types.js +17 -1
- package/dist/ampersend/types.js.map +1 -1
- package/dist/cli/ampersend.js +45 -2
- package/dist/cli/ampersend.js.map +1 -1
- package/dist/cli/commands/agent.d.ts +22 -0
- package/dist/cli/commands/agent.d.ts.map +1 -0
- package/dist/cli/commands/agent.js +144 -0
- package/dist/cli/commands/agent.js.map +1 -0
- package/dist/cli/commands/card.d.ts +125 -0
- package/dist/cli/commands/card.d.ts.map +1 -0
- package/dist/cli/commands/card.js +399 -0
- package/dist/cli/commands/card.js.map +1 -0
- package/dist/cli/commands/fetch.d.ts +76 -2
- package/dist/cli/commands/fetch.d.ts.map +1 -1
- package/dist/cli/commands/fetch.js +208 -128
- package/dist/cli/commands/fetch.js.map +1 -1
- package/dist/cli/commands/fund.d.ts +3 -0
- package/dist/cli/commands/fund.d.ts.map +1 -0
- package/dist/cli/commands/fund.js +22 -0
- package/dist/cli/commands/fund.js.map +1 -0
- package/dist/cli/commands/marketplace.d.ts +3 -0
- package/dist/cli/commands/marketplace.d.ts.map +1 -1
- package/dist/cli/commands/marketplace.js +23 -4
- package/dist/cli/commands/marketplace.js.map +1 -1
- package/dist/cli/commands/version.d.ts +3 -0
- package/dist/cli/commands/version.d.ts.map +1 -0
- package/dist/cli/commands/version.js +12 -0
- package/dist/cli/commands/version.js.map +1 -0
- package/dist/cli/config.d.ts +58 -0
- package/dist/cli/config.d.ts.map +1 -1
- package/dist/cli/config.js +105 -1
- package/dist/cli/config.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp/proxy/cli.js +1 -0
- package/dist/mcp/proxy/cli.js.map +1 -1
- package/dist/mcp/proxy/factory.d.ts +2 -0
- package/dist/mcp/proxy/factory.d.ts.map +1 -1
- package/dist/mcp/proxy/factory.js +10 -1
- package/dist/mcp/proxy/factory.js.map +1 -1
- package/dist/mcp/proxy/server/init.js +1 -1
- package/dist/mcp/proxy/server/init.js.map +1 -1
- package/dist/mcp/proxy/server/server.d.ts +3 -1
- package/dist/mcp/proxy/server/server.d.ts.map +1 -1
- package/dist/mcp/proxy/server/server.js +5 -2
- package/dist/mcp/proxy/server/server.js.map +1 -1
- package/dist/mcp/proxy/types.d.ts +7 -0
- package/dist/mcp/proxy/types.d.ts.map +1 -1
- package/dist/mcp/proxy/types.js.map +1 -1
- package/dist/version.d.ts +3 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +3 -1
- package/dist/version.js.map +1 -1
- package/dist/x402/http/factory.d.ts +2 -0
- package/dist/x402/http/factory.d.ts.map +1 -1
- package/dist/x402/http/factory.js +1 -0
- package/dist/x402/http/factory.js.map +1 -1
- package/dist/x402/index.d.ts +2 -0
- package/dist/x402/index.d.ts.map +1 -1
- package/dist/x402/index.js +2 -0
- package/dist/x402/index.js.map +1 -1
- package/dist/x402/siwx.d.ts +55 -0
- package/dist/x402/siwx.d.ts.map +1 -0
- package/dist/x402/siwx.js +122 -0
- package/dist/x402/siwx.js.map +1 -0
- package/dist/x402/wallets/smart-account/cosigned.d.ts +9 -2
- package/dist/x402/wallets/smart-account/cosigned.d.ts.map +1 -1
- package/dist/x402/wallets/smart-account/cosigned.js +13 -4
- package/dist/x402/wallets/smart-account/cosigned.js.map +1 -1
- package/package.json +3 -2
package/dist/x402/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/x402/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAK5G,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAGzC,yBAAyB;AACzB,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAA;AAG9F,mBAAmB;AACnB,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,wBAAwB,EACxB,yBAAyB,GAC1B,MAAM,iBAAiB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/x402/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAK5G,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAGzC,yBAAyB;AACzB,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAA;AAG9F,mBAAmB;AACnB,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,wBAAwB,EACxB,yBAAyB,GAC1B,MAAM,iBAAiB,CAAA;AAGxB,6BAA6B;AAC7B,OAAO,EAAE,gBAAgB,EAAE,0BAA0B,EAAE,MAAM,WAAW,CAAA"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sign-In-With-X (SIWX) integration for Ampersend smart accounts.
|
|
3
|
+
*
|
|
4
|
+
* Every ERC-1271 signature out of an Ampersend Safe is gated by
|
|
5
|
+
* CoSignerValidator (session key + service key). This module wires that
|
|
6
|
+
* dual-sig requirement into the SIWX client flow: session key signs the SIWE
|
|
7
|
+
* message hash locally, the API co-signs the same hash, the pair is packed
|
|
8
|
+
* into a CoSignerValidator envelope, and the result becomes the SIWX
|
|
9
|
+
* signature. Servers MUST verify via ERC-1271 (e.g. `publicClient.verifyMessage`).
|
|
10
|
+
*/
|
|
11
|
+
import { type EVMSigner } from "@x402/extensions/sign-in-with-x";
|
|
12
|
+
import { type Address, type Hex } from "viem";
|
|
13
|
+
export interface SiwxSignerConfig {
|
|
14
|
+
/** Smart account address — the SIWX-claimed identity and the payment-history address. */
|
|
15
|
+
smartAccountAddress: Address;
|
|
16
|
+
/** Session key authorized via CoSignerValidator to sign for the smart account. */
|
|
17
|
+
sessionKeyPrivateKey: Hex;
|
|
18
|
+
/** Ampersend API base URL. */
|
|
19
|
+
apiUrl: string;
|
|
20
|
+
/** CoSignerValidator address. Defaults to the standard CoSignerValidator. */
|
|
21
|
+
validatorAddress?: Address;
|
|
22
|
+
/** Client name for product-analytics attribution. Defaults to `sdk-typescript`. */
|
|
23
|
+
clientName?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Build an EVMSigner that signs SIWX messages as the smart account.
|
|
27
|
+
*
|
|
28
|
+
* Each `signMessage` call dispatches a co-sign request to the Ampersend API,
|
|
29
|
+
* so SIWX inherits the same liveness + policy boundary as payments. The
|
|
30
|
+
* returned signature is a CoSignerValidator ERC-1271 envelope: server
|
|
31
|
+
* verifiers call the Safe's `isValidSignature`, which routes to
|
|
32
|
+
* CoSignerValidator, which recovers both keys against `hashMessage(message)`.
|
|
33
|
+
*/
|
|
34
|
+
export declare function createSiwxSigner(config: SiwxSignerConfig): EVMSigner;
|
|
35
|
+
/**
|
|
36
|
+
* Wrap a fetch implementation so SIWX 402 challenges are satisfied
|
|
37
|
+
* automatically, signing as the configured smart account.
|
|
38
|
+
*
|
|
39
|
+
* Pair with `wrapFetchWithPayment` from `@x402/fetch`, putting SIWX **inside**
|
|
40
|
+
* the payment wrapper. SIWX handles auth-only routes and re-entry to
|
|
41
|
+
* previously-paid resources; anything else (no SIWX extension, signature
|
|
42
|
+
* rejected) falls through unchanged to the payment wrapper.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* const fetchWithSiwx = wrapFetchWithAmpersendSiwx(fetch, {
|
|
47
|
+
* smartAccountAddress,
|
|
48
|
+
* sessionKeyPrivateKey,
|
|
49
|
+
* apiUrl,
|
|
50
|
+
* })
|
|
51
|
+
* const fetchWithPayment = wrapFetchWithPayment(fetchWithSiwx, ampersendClient)
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare function wrapFetchWithAmpersendSiwx(fetchImpl: typeof globalThis.fetch, config: SiwxSignerConfig): typeof globalThis.fetch;
|
|
55
|
+
//# sourceMappingURL=siwx.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"siwx.d.ts","sourceRoot":"","sources":["../../src/x402/siwx.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAIL,KAAK,SAAS,EAEf,MAAM,iCAAiC,CAAA;AACxC,OAAO,EAAe,KAAK,OAAO,EAAE,KAAK,GAAG,EAAwB,MAAM,MAAM,CAAA;AAOhF,MAAM,WAAW,gBAAgB;IAC/B,yFAAyF;IACzF,mBAAmB,EAAE,OAAO,CAAA;IAC5B,kFAAkF;IAClF,oBAAoB,EAAE,GAAG,CAAA;IACzB,8BAA8B;IAC9B,MAAM,EAAE,MAAM,CAAA;IACd,6EAA6E;IAC7E,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,mFAAmF;IACnF,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAYD;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,gBAAgB,GAAG,SAAS,CA6BpE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,OAAO,UAAU,CAAC,KAAK,EAClC,MAAM,EAAE,gBAAgB,GACvB,OAAO,UAAU,CAAC,KAAK,CA0CzB"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sign-In-With-X (SIWX) integration for Ampersend smart accounts.
|
|
3
|
+
*
|
|
4
|
+
* Every ERC-1271 signature out of an Ampersend Safe is gated by
|
|
5
|
+
* CoSignerValidator (session key + service key). This module wires that
|
|
6
|
+
* dual-sig requirement into the SIWX client flow: session key signs the SIWE
|
|
7
|
+
* message hash locally, the API co-signs the same hash, the pair is packed
|
|
8
|
+
* into a CoSignerValidator envelope, and the result becomes the SIWX
|
|
9
|
+
* signature. Servers MUST verify via ERC-1271 (e.g. `publicClient.verifyMessage`).
|
|
10
|
+
*/
|
|
11
|
+
import { decodePaymentRequiredHeader } from "@x402/core/http";
|
|
12
|
+
import { createSIWxPayload, encodeSIWxHeader, SIGN_IN_WITH_X, } from "@x402/extensions/sign-in-with-x";
|
|
13
|
+
import { hashMessage } from "viem";
|
|
14
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
15
|
+
import { ApiClient } from "../ampersend/client.js";
|
|
16
|
+
import { COSIGNER_VALIDATOR } from "../smart-account/constants.js";
|
|
17
|
+
import { encodeCoSignerEnvelope } from "./wallets/smart-account/cosigned.js";
|
|
18
|
+
/**
|
|
19
|
+
* Normalize viem's `SignableMessage` to the raw string SIWE produces.
|
|
20
|
+
* SIWX message bodies are always strings per CAIP-122; reject the `{ raw }`
|
|
21
|
+
* shape rather than guess what to send to the API for parsing.
|
|
22
|
+
*/
|
|
23
|
+
function requireStringMessage(message) {
|
|
24
|
+
if (typeof message === "string")
|
|
25
|
+
return message;
|
|
26
|
+
throw new Error("SIWX signer received a non-string message; SIWE messages must be strings");
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Build an EVMSigner that signs SIWX messages as the smart account.
|
|
30
|
+
*
|
|
31
|
+
* Each `signMessage` call dispatches a co-sign request to the Ampersend API,
|
|
32
|
+
* so SIWX inherits the same liveness + policy boundary as payments. The
|
|
33
|
+
* returned signature is a CoSignerValidator ERC-1271 envelope: server
|
|
34
|
+
* verifiers call the Safe's `isValidSignature`, which routes to
|
|
35
|
+
* CoSignerValidator, which recovers both keys against `hashMessage(message)`.
|
|
36
|
+
*/
|
|
37
|
+
export function createSiwxSigner(config) {
|
|
38
|
+
const validatorAddress = config.validatorAddress ?? COSIGNER_VALIDATOR;
|
|
39
|
+
const sessionKeyAccount = privateKeyToAccount(config.sessionKeyPrivateKey);
|
|
40
|
+
const apiClient = new ApiClient({
|
|
41
|
+
baseUrl: config.apiUrl,
|
|
42
|
+
sessionKeyPrivateKey: config.sessionKeyPrivateKey,
|
|
43
|
+
agentAddress: config.smartAccountAddress,
|
|
44
|
+
...(config.clientName !== undefined ? { clientName: config.clientName } : {}),
|
|
45
|
+
});
|
|
46
|
+
return {
|
|
47
|
+
address: config.smartAccountAddress,
|
|
48
|
+
signMessage: async ({ message }) => {
|
|
49
|
+
const messageString = requireStringMessage(message);
|
|
50
|
+
// viem's verifyMessage passes hashMessage(message) to the Safe's
|
|
51
|
+
// isValidSignature; CoSignerValidator's `_validateDualSignature` then
|
|
52
|
+
// calls `ECDSA.recover(hash, sig)` directly — no further EIP-191
|
|
53
|
+
// wrapping. Both signatures MUST be raw ECDSA over this exact hash,
|
|
54
|
+
// not signMessage({ raw }) (which would re-prefix and recover wrong).
|
|
55
|
+
const messageHash = hashMessage(messageString);
|
|
56
|
+
const [agentSignature, { serverSignature }] = await Promise.all([
|
|
57
|
+
sessionKeyAccount.sign({ hash: messageHash }),
|
|
58
|
+
apiClient.signSiwxChallenge(messageString),
|
|
59
|
+
]);
|
|
60
|
+
return encodeCoSignerEnvelope(agentSignature, serverSignature, validatorAddress);
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Wrap a fetch implementation so SIWX 402 challenges are satisfied
|
|
66
|
+
* automatically, signing as the configured smart account.
|
|
67
|
+
*
|
|
68
|
+
* Pair with `wrapFetchWithPayment` from `@x402/fetch`, putting SIWX **inside**
|
|
69
|
+
* the payment wrapper. SIWX handles auth-only routes and re-entry to
|
|
70
|
+
* previously-paid resources; anything else (no SIWX extension, signature
|
|
71
|
+
* rejected) falls through unchanged to the payment wrapper.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* const fetchWithSiwx = wrapFetchWithAmpersendSiwx(fetch, {
|
|
76
|
+
* smartAccountAddress,
|
|
77
|
+
* sessionKeyPrivateKey,
|
|
78
|
+
* apiUrl,
|
|
79
|
+
* })
|
|
80
|
+
* const fetchWithPayment = wrapFetchWithPayment(fetchWithSiwx, ampersendClient)
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export function wrapFetchWithAmpersendSiwx(fetchImpl, config) {
|
|
84
|
+
const signer = createSiwxSigner(config);
|
|
85
|
+
// Upstream `wrapFetchWithSIWx` keys chain selection off `accepts[0].network`,
|
|
86
|
+
// which breaks auth-only routes (`accepts: []`) — they hand off to the
|
|
87
|
+
// payment wrapper which then errors on the empty accepts array. We pick the
|
|
88
|
+
// chain from `accepts[0]` when present, otherwise fall back to the first
|
|
89
|
+
// entry in `supportedChains`. Loop guard via the SIWX header is preserved.
|
|
90
|
+
return async (input, init) => {
|
|
91
|
+
const request = new Request(input, init);
|
|
92
|
+
const clonedRequest = request.clone();
|
|
93
|
+
const response = await fetchImpl(request);
|
|
94
|
+
if (response.status !== 402)
|
|
95
|
+
return response;
|
|
96
|
+
const paymentRequiredHeader = response.headers.get("PAYMENT-REQUIRED");
|
|
97
|
+
if (!paymentRequiredHeader)
|
|
98
|
+
return response;
|
|
99
|
+
const paymentRequired = decodePaymentRequiredHeader(paymentRequiredHeader);
|
|
100
|
+
const siwxExtension = paymentRequired.extensions?.[SIGN_IN_WITH_X];
|
|
101
|
+
if (!siwxExtension?.supportedChains?.length)
|
|
102
|
+
return response;
|
|
103
|
+
if (clonedRequest.headers.has(SIGN_IN_WITH_X)) {
|
|
104
|
+
throw new Error("SIWX authentication already attempted");
|
|
105
|
+
}
|
|
106
|
+
const paymentNetwork = paymentRequired.accepts?.[0]?.network;
|
|
107
|
+
const matchingChain = paymentNetwork
|
|
108
|
+
? siwxExtension.supportedChains.find((c) => c.chainId === paymentNetwork)
|
|
109
|
+
: siwxExtension.supportedChains[0];
|
|
110
|
+
if (!matchingChain)
|
|
111
|
+
return response;
|
|
112
|
+
const completeInfo = {
|
|
113
|
+
...siwxExtension.info,
|
|
114
|
+
chainId: matchingChain.chainId,
|
|
115
|
+
type: matchingChain.type,
|
|
116
|
+
};
|
|
117
|
+
const payload = await createSIWxPayload(completeInfo, signer);
|
|
118
|
+
clonedRequest.headers.set(SIGN_IN_WITH_X, encodeSIWxHeader(payload));
|
|
119
|
+
return fetchImpl(clonedRequest);
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=siwx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"siwx.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DSA signatures into a CoSignerValidator ERC-1271 envelope:
|
|
11
|
+
* `abi.encode(agentSig, serverSig)` then `encodePacked(validator, combined)`
|
|
12
|
+
* (ERC-7579 nested-validator framing). Both signatures MUST be over the same
|
|
13
|
+
* digest that the validator will recover against.
|
|
14
|
+
*/
|
|
15
|
+
export declare function encodeCoSignerEnvelope(agentSignature: Hex, serverSignature: Hex, validator: Address): Hex;
|
|
16
|
+
/**
|
|
17
|
+
* CoSignerValidator ERC-1271 signature for EIP-712 typed data: agent signs the
|
|
18
|
+
* typed data, then the pair is packed via {@link encodeCoSignerEnvelope}.
|
|
12
19
|
*/
|
|
13
20
|
export declare function encodeCoSignedERC1271Signature(agentPrivateKey: Hex, typedDataParams: TypedDataDefinition, serverSignature: Hex, coSignerValidatorAddress: Address): Promise<Hex>;
|
|
14
21
|
/**
|
|
@@ -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;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,
|
|
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;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,cAAc,EAAE,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,GAAG,GAAG,CAGzG;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,CAId;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"}
|
|
@@ -4,14 +4,23 @@ import { TRANSFER_WITH_AUTHORIZATION_TYPE } from "../../../smart-account/eip712-
|
|
|
4
4
|
import { acceptedOf, buildAuthorization } from "../../envelopes.js";
|
|
5
5
|
import { chainIdOf } from "./chain.js";
|
|
6
6
|
/**
|
|
7
|
-
* CoSignerValidator ERC-1271
|
|
8
|
-
*
|
|
7
|
+
* Pack a pair of ECDSA signatures into a CoSignerValidator ERC-1271 envelope:
|
|
8
|
+
* `abi.encode(agentSig, serverSig)` then `encodePacked(validator, combined)`
|
|
9
|
+
* (ERC-7579 nested-validator framing). Both signatures MUST be over the same
|
|
10
|
+
* digest that the validator will recover against.
|
|
11
|
+
*/
|
|
12
|
+
export function encodeCoSignerEnvelope(agentSignature, serverSignature, validator) {
|
|
13
|
+
const combined = encodeAbiParameters([{ type: "bytes" }, { type: "bytes" }], [agentSignature, serverSignature]);
|
|
14
|
+
return encodePacked(["address", "bytes"], [validator, combined]);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* CoSignerValidator ERC-1271 signature for EIP-712 typed data: agent signs the
|
|
18
|
+
* typed data, then the pair is packed via {@link encodeCoSignerEnvelope}.
|
|
9
19
|
*/
|
|
10
20
|
export async function encodeCoSignedERC1271Signature(agentPrivateKey, typedDataParams, serverSignature, coSignerValidatorAddress) {
|
|
11
21
|
const agentAccount = privateKeyToAccount(agentPrivateKey);
|
|
12
22
|
const agentSignature = await agentAccount.signTypedData(typedDataParams);
|
|
13
|
-
|
|
14
|
-
return encodePacked(["address", "bytes"], [coSignerValidatorAddress, combinedSignature]);
|
|
23
|
+
return encodeCoSignerEnvelope(agentSignature, serverSignature, coSignerValidatorAddress);
|
|
15
24
|
}
|
|
16
25
|
/**
|
|
17
26
|
* Sign a co-signed `exact` instruction. Server supplies ERC-3009
|
|
@@ -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;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
|
|
1
|
+
{"version":3,"file":"cosigned.js","sourceRoot":"","sources":["../../../../src/x402/wallets/smart-account/cosigned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,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"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ampersend_ai/ampersend-sdk",
|
|
3
3
|
"description": "Tooling for building applications with x402 payment capabilities. Supports buyer and seller roles.",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.25",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -66,10 +66,11 @@
|
|
|
66
66
|
"@types/express": "^5.0.6",
|
|
67
67
|
"@x402/core": "2.9.0",
|
|
68
68
|
"@x402/evm": "2.9.0",
|
|
69
|
+
"@x402/extensions": "2.9.0",
|
|
69
70
|
"@x402/fetch": "2.9.0",
|
|
70
71
|
"async-mutex": "^0.5.0",
|
|
71
72
|
"commander": "^12.1.0",
|
|
72
|
-
"effect": "^3.21.
|
|
73
|
+
"effect": "^3.21.2",
|
|
73
74
|
"express": "^5.2.1",
|
|
74
75
|
"fastmcp": "npm:@ampersend_ai/fastmcp@^1.0.0",
|
|
75
76
|
"siwe": "^3.0.0",
|