@ampersend_ai/ampersend-sdk 0.0.11 → 0.0.13
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 +52 -0
- package/dist/ampersend/approval.d.ts.map +1 -0
- package/dist/ampersend/approval.js +106 -0
- package/dist/ampersend/approval.js.map +1 -0
- package/dist/ampersend/index.d.ts +1 -0
- package/dist/ampersend/index.d.ts.map +1 -1
- package/dist/ampersend/index.js +1 -0
- package/dist/ampersend/index.js.map +1 -1
- package/dist/ampersend/management.d.ts +2 -2
- package/dist/ampersend/treasurer.d.ts +2 -1
- package/dist/ampersend/treasurer.d.ts.map +1 -1
- package/dist/ampersend/treasurer.js +16 -4
- package/dist/ampersend/treasurer.js.map +1 -1
- package/dist/ampersend/types.d.ts +207 -4
- package/dist/ampersend/types.d.ts.map +1 -1
- package/dist/ampersend/types.js +107 -2
- package/dist/ampersend/types.js.map +1 -1
- package/dist/cli/ampersend.js +2 -0
- package/dist/cli/ampersend.js.map +1 -1
- package/dist/cli/commands/config.d.ts +1 -1
- package/dist/cli/commands/config.d.ts.map +1 -1
- package/dist/cli/commands/config.js +41 -35
- package/dist/cli/commands/config.js.map +1 -1
- package/dist/cli/commands/fetch.js +6 -6
- package/dist/cli/commands/fetch.js.map +1 -1
- package/dist/cli/commands/setup.d.ts +18 -0
- package/dist/cli/commands/setup.d.ts.map +1 -0
- package/dist/cli/commands/setup.js +151 -0
- package/dist/cli/commands/setup.js.map +1 -0
- package/dist/cli/config.d.ts +62 -38
- package/dist/cli/config.d.ts.map +1 -1
- package/dist/cli/config.js +148 -110
- package/dist/cli/config.js.map +1 -1
- package/dist/smart-account/constants.d.ts +5 -0
- package/dist/smart-account/constants.d.ts.map +1 -1
- package/dist/smart-account/constants.js +5 -0
- package/dist/smart-account/constants.js.map +1 -1
- package/dist/smart-account/eip712-types.d.ts +27 -0
- package/dist/smart-account/eip712-types.d.ts.map +1 -0
- package/dist/smart-account/eip712-types.js +16 -0
- package/dist/smart-account/eip712-types.js.map +1 -0
- package/dist/smart-account/index.d.ts +2 -1
- package/dist/smart-account/index.d.ts.map +1 -1
- package/dist/smart-account/index.js +2 -1
- package/dist/smart-account/index.js.map +1 -1
- package/dist/smart-account/signing.d.ts.map +1 -1
- package/dist/smart-account/signing.js +2 -8
- package/dist/smart-account/signing.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/x402/index.d.ts +1 -0
- package/dist/x402/index.d.ts.map +1 -1
- package/dist/x402/index.js.map +1 -1
- package/dist/x402/types.d.ts +36 -0
- package/dist/x402/types.d.ts.map +1 -0
- package/dist/x402/types.js +9 -0
- package/dist/x402/types.js.map +1 -0
- package/dist/x402/wallet.d.ts +3 -1
- package/dist/x402/wallet.d.ts.map +1 -1
- package/dist/x402/wallet.js.map +1 -1
- package/dist/x402/wallets/account/wallet.d.ts +5 -3
- package/dist/x402/wallets/account/wallet.d.ts.map +1 -1
- package/dist/x402/wallets/account/wallet.js +2 -1
- package/dist/x402/wallets/account/wallet.js.map +1 -1
- package/dist/x402/wallets/index.d.ts +1 -0
- package/dist/x402/wallets/index.d.ts.map +1 -1
- package/dist/x402/wallets/index.js +1 -0
- package/dist/x402/wallets/index.js.map +1 -1
- package/dist/x402/wallets/smart-account/cosigned.d.ts +46 -0
- package/dist/x402/wallets/smart-account/cosigned.d.ts.map +1 -0
- package/dist/x402/wallets/smart-account/cosigned.js +90 -0
- package/dist/x402/wallets/smart-account/cosigned.js.map +1 -0
- package/dist/x402/wallets/smart-account/wallet.d.ts +8 -1
- package/dist/x402/wallets/smart-account/wallet.d.ts.map +1 -1
- package/dist/x402/wallets/smart-account/wallet.js +14 -3
- package/dist/x402/wallets/smart-account/wallet.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared EIP-712 type definitions for ERC-3009 TransferWithAuthorization
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* ERC-3009 TransferWithAuthorization message type
|
|
6
|
+
* Used by USDC and other ERC-3009 compliant tokens for gasless transfers
|
|
7
|
+
*/
|
|
8
|
+
export const TRANSFER_WITH_AUTHORIZATION_TYPE = [
|
|
9
|
+
{ name: "from", type: "address" },
|
|
10
|
+
{ name: "to", type: "address" },
|
|
11
|
+
{ name: "value", type: "uint256" },
|
|
12
|
+
{ name: "validAfter", type: "uint256" },
|
|
13
|
+
{ name: "validBefore", type: "uint256" },
|
|
14
|
+
{ name: "nonce", type: "bytes32" },
|
|
15
|
+
];
|
|
16
|
+
//# sourceMappingURL=eip712-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eip712-types.js","sourceRoot":"","sources":["../../src/smart-account/eip712-types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG;IAC9C,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE;IACjC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE;IAC/B,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE;IAClC,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE;IACvC,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,SAAS,EAAE;IACxC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE;CAC1B,CAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { OWNABLE_VALIDATOR } from "./constants.ts";
|
|
1
|
+
export { COSIGNER_VALIDATOR, OWNABLE_VALIDATOR } from "./constants.ts";
|
|
2
|
+
export { TRANSFER_WITH_AUTHORIZATION_TYPE } from "./eip712-types.ts";
|
|
2
3
|
export { signERC3009Authorization, signSmartAccountTypedData } from "./signing.ts";
|
|
3
4
|
export type { ERC3009AuthorizationData } from "./types.ts";
|
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/smart-account/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/smart-account/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AACtE,OAAO,EAAE,gCAAgC,EAAE,MAAM,mBAAmB,CAAA;AACpE,OAAO,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AAClF,YAAY,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export { OWNABLE_VALIDATOR } from "./constants.js";
|
|
1
|
+
export { COSIGNER_VALIDATOR, OWNABLE_VALIDATOR } from "./constants.js";
|
|
2
|
+
export { TRANSFER_WITH_AUTHORIZATION_TYPE } from "./eip712-types.js";
|
|
2
3
|
export { signERC3009Authorization, signSmartAccountTypedData } from "./signing.js";
|
|
3
4
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/smart-account/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/smart-account/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AACtE,OAAO,EAAE,gCAAgC,EAAE,MAAM,mBAAmB,CAAA;AACpE,OAAO,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signing.d.ts","sourceRoot":"","sources":["../../src/smart-account/signing.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"signing.d.ts","sourceRoot":"","sources":["../../src/smart-account/signing.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,MAAM,CAAA;AAIxE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAA;AAE1D;;;;;;;;GAQG;AACH,wBAAsB,yBAAyB,CAC7C,KAAK,CAAC,SAAS,SAAS,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC3D,WAAW,SAAS,MAAM,SAAS,GAAG,cAAc,GAAG,MAAM,SAAS,EAEtE,oBAAoB,EAAE,GAAG,EACzB,mBAAmB,EAAE,OAAO,EAC5B,MAAM,EAAE,mBAAmB,CAAC,SAAS,EAAE,WAAW,CAAC,EACnD,gBAAgB,EAAE,OAAO,GACxB,OAAO,CAAC,GAAG,CAAC,CAqBd;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,wBAAwB,CAC5C,oBAAoB,EAAE,GAAG,EACzB,mBAAmB,EAAE,OAAO,EAC5B,QAAQ,EAAE,wBAAwB,EAClC,YAAY,EAAE,OAAO,EACrB,OAAO,EAAE,MAAM,EACf,gBAAgB,EAAE,OAAO,EACzB,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,GAAG,CAAC,CA2Bd"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { encode1271Signature, getAccount, getOwnableValidatorSignature } from "@rhinestone/module-sdk";
|
|
2
2
|
import { privateKeyToAccount } from "viem/accounts";
|
|
3
|
+
import { TRANSFER_WITH_AUTHORIZATION_TYPE } from "./eip712-types.js";
|
|
3
4
|
/**
|
|
4
5
|
* Generic smart account typed data signing with OwnableValidator
|
|
5
6
|
*
|
|
@@ -54,14 +55,7 @@ export async function signERC3009Authorization(sessionKeyPrivateKey, smartAccoun
|
|
|
54
55
|
verifyingContract: tokenAddress,
|
|
55
56
|
},
|
|
56
57
|
types: {
|
|
57
|
-
TransferWithAuthorization:
|
|
58
|
-
{ name: "from", type: "address" },
|
|
59
|
-
{ name: "to", type: "address" },
|
|
60
|
-
{ name: "value", type: "uint256" },
|
|
61
|
-
{ name: "validAfter", type: "uint256" },
|
|
62
|
-
{ name: "validBefore", type: "uint256" },
|
|
63
|
-
{ name: "nonce", type: "bytes32" },
|
|
64
|
-
],
|
|
58
|
+
TransferWithAuthorization: TRANSFER_WITH_AUTHORIZATION_TYPE,
|
|
65
59
|
},
|
|
66
60
|
primaryType: "TransferWithAuthorization",
|
|
67
61
|
message: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signing.js","sourceRoot":"","sources":["../../src/smart-account/signing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAA;AAEtG,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"signing.js","sourceRoot":"","sources":["../../src/smart-account/signing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAA;AAEtG,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AAEnD,OAAO,EAAE,gCAAgC,EAAE,MAAM,mBAAmB,CAAA;AAGpE;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAI7C,oBAAyB,EACzB,mBAA4B,EAC5B,MAAmD,EACnD,gBAAyB;IAEzB,yCAAyC;IACzC,MAAM,iBAAiB,GAAG,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index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export type { Authorization, PaymentContext, PaymentStatus, X402Treasurer } from "./treasurer.ts";
|
|
2
|
+
export type { ERC3009AuthorizationData, ServerAuthorizationData } from "./types.ts";
|
|
2
3
|
export { WalletError } from "./wallet.ts";
|
|
3
4
|
export type { X402Wallet } from "./wallet.ts";
|
|
4
5
|
export { AccountWallet, SmartAccountWallet, createWalletFromConfig } from "./wallets/index.ts";
|
package/dist/x402/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/x402/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AACjG,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzC,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAG7C,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAA;AAC9F,YAAY,EAAE,kBAAkB,EAAE,YAAY,EAAE,eAAe,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAA;AAGrH,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/x402/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AACjG,YAAY,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAA;AACnF,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzC,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAG7C,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAA;AAC9F,YAAY,EAAE,kBAAkB,EAAE,YAAY,EAAE,eAAe,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAA;AAGrH,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA"}
|
package/dist/x402/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/x402/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/x402/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAGzC,yBAAyB;AACzB,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAA;AAG9F,eAAe;AACf,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types for the x402 payment layer.
|
|
3
|
+
*
|
|
4
|
+
* These are plain interfaces used by the x402 wallet abstraction.
|
|
5
|
+
* The ampersend-specific layer (ampersend/types.ts) defines Effect Schema
|
|
6
|
+
* classes that are structurally compatible with these interfaces.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* ERC-3009 TransferWithAuthorization data fields.
|
|
10
|
+
* Used by wallets to construct EIP-712 typed data for signing.
|
|
11
|
+
*/
|
|
12
|
+
export interface ERC3009AuthorizationData {
|
|
13
|
+
/** Sender address (agent smart account) */
|
|
14
|
+
from: string;
|
|
15
|
+
/** Recipient address (seller) */
|
|
16
|
+
to: string;
|
|
17
|
+
/** Transfer amount in wei (stringified bigint) */
|
|
18
|
+
value: string;
|
|
19
|
+
/** Unix timestamp after which the authorization is valid (stringified bigint) */
|
|
20
|
+
validAfter: string;
|
|
21
|
+
/** Unix timestamp before which the authorization expires (stringified bigint) */
|
|
22
|
+
validBefore: string;
|
|
23
|
+
/** Random 32-byte nonce as hex string for replay protection */
|
|
24
|
+
nonce: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Server co-signature data for co-signed agent keys.
|
|
28
|
+
* Provided by the Ampersend API when authorizing payments for co-signed keys.
|
|
29
|
+
*/
|
|
30
|
+
export interface ServerAuthorizationData {
|
|
31
|
+
/** ERC-3009 TransferWithAuthorization data */
|
|
32
|
+
authorizationData: ERC3009AuthorizationData;
|
|
33
|
+
/** Server's ECDSA signature (65 bytes as hex string) */
|
|
34
|
+
serverSignature: string;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/x402/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;GAGG;AACH,MAAM,WAAW,wBAAwB;IACvC,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAA;IACZ,iCAAiC;IACjC,EAAE,EAAE,MAAM,CAAA;IACV,kDAAkD;IAClD,KAAK,EAAE,MAAM,CAAA;IACb,iFAAiF;IACjF,UAAU,EAAE,MAAM,CAAA;IAClB,iFAAiF;IACjF,WAAW,EAAE,MAAM,CAAA;IACnB,+DAA+D;IAC/D,KAAK,EAAE,MAAM,CAAA;CACd;AAED;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACtC,8CAA8C;IAC9C,iBAAiB,EAAE,wBAAwB,CAAA;IAC3C,wDAAwD;IACxD,eAAe,EAAE,MAAM,CAAA;CACxB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types for the x402 payment layer.
|
|
3
|
+
*
|
|
4
|
+
* These are plain interfaces used by the x402 wallet abstraction.
|
|
5
|
+
* The ampersend-specific layer (ampersend/types.ts) defines Effect Schema
|
|
6
|
+
* classes that are structurally compatible with these interfaces.
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/x402/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
package/dist/x402/wallet.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { PaymentPayload, PaymentRequirements } from "x402/types";
|
|
2
|
+
import type { ServerAuthorizationData } from "./types.ts";
|
|
2
3
|
/**
|
|
3
4
|
* Error thrown when wallet cannot create a payment
|
|
4
5
|
*/
|
|
@@ -33,9 +34,10 @@ export interface X402Wallet {
|
|
|
33
34
|
* Creates a payment payload from requirements.
|
|
34
35
|
*
|
|
35
36
|
* @param requirements - Payment requirements from seller
|
|
37
|
+
* @param serverAuthorization - Optional server co-signature data (for co-signed smart account keys)
|
|
36
38
|
* @returns Signed payment payload ready for submission
|
|
37
39
|
* @throws {WalletError} If unable to create payment (unsupported scheme, insufficient funds, etc.)
|
|
38
40
|
*/
|
|
39
|
-
createPayment(requirements: PaymentRequirements): Promise<PaymentPayload>;
|
|
41
|
+
createPayment(requirements: PaymentRequirements, serverAuthorization?: ServerAuthorizationData): Promise<PaymentPayload>;
|
|
40
42
|
}
|
|
41
43
|
//# sourceMappingURL=wallet.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/x402/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAErE;;GAEG;AACH,qBAAa,WAAY,SAAQ,KAAK;IAG3B,KAAK,CAAC,EAAE,KAAK;gBADpB,OAAO,EAAE,MAAM,EACR,KAAK,CAAC,EAAE,KAAK,YAAA;CAKvB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,WAAW,UAAU;IACzB
|
|
1
|
+
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/x402/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAErE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAA;AAEzD;;GAEG;AACH,qBAAa,WAAY,SAAQ,KAAK;IAG3B,KAAK,CAAC,EAAE,KAAK;gBADpB,OAAO,EAAE,MAAM,EACR,KAAK,CAAC,EAAE,KAAK,YAAA;CAKvB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,WAAW,UAAU;IACzB;;;;;;;OAOG;IACH,aAAa,CACX,YAAY,EAAE,mBAAmB,EACjC,mBAAmB,CAAC,EAAE,uBAAuB,GAC5C,OAAO,CAAC,cAAc,CAAC,CAAA;CAC3B"}
|
package/dist/x402/wallet.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../src/x402/wallet.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../src/x402/wallet.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,OAAO,WAAY,SAAQ,KAAK;IAG3B;IAFT,YACE,OAAe,EACR,KAAa;QAEpB,KAAK,CAAC,OAAO,CAAC,CAAA;QAFP,UAAK,GAAL,KAAK,CAAQ;QAGpB,IAAI,CAAC,IAAI,GAAG,aAAa,CAAA;IAC3B,CAAC;CACF"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Hex, LocalAccount } from "viem";
|
|
2
2
|
import type { PaymentPayload, PaymentRequirements } from "x402/types";
|
|
3
|
+
import type { ServerAuthorizationData } from "../../../ampersend/types.ts";
|
|
3
4
|
import { type X402Wallet } from "../../wallet.ts";
|
|
4
5
|
/**
|
|
5
6
|
* AccountWallet - EOA (Externally Owned Account) wallet implementation
|
|
@@ -21,7 +22,7 @@ import { type X402Wallet } from "../../wallet.ts";
|
|
|
21
22
|
*/
|
|
22
23
|
export declare class AccountWallet implements X402Wallet {
|
|
23
24
|
private account;
|
|
24
|
-
constructor(account:
|
|
25
|
+
constructor(account: LocalAccount);
|
|
25
26
|
/**
|
|
26
27
|
* Creates an AccountWallet from a private key
|
|
27
28
|
*/
|
|
@@ -29,8 +30,9 @@ export declare class AccountWallet implements X402Wallet {
|
|
|
29
30
|
/**
|
|
30
31
|
* Creates a payment payload from requirements.
|
|
31
32
|
* Only supports "exact" payment scheme.
|
|
33
|
+
* Note: serverAuthorization parameter is ignored for EOA wallets (only used by SmartAccountWallet)
|
|
32
34
|
*/
|
|
33
|
-
createPayment(requirements: PaymentRequirements): Promise<PaymentPayload>;
|
|
35
|
+
createPayment(requirements: PaymentRequirements, _serverAuthorization?: ServerAuthorizationData): Promise<PaymentPayload>;
|
|
34
36
|
/**
|
|
35
37
|
* Returns the account address
|
|
36
38
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../../../src/x402/wallets/account/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../../../src/x402/wallets/account/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAG7C,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAErE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAA;AAC1E,OAAO,EAAe,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAE9D;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,aAAc,YAAW,UAAU;IAC9C,OAAO,CAAC,OAAO,CAAc;gBAEjB,OAAO,EAAE,YAAY;IAIjC;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,GAAG,GAAG,aAAa;IAIrD;;;;OAIG;IACG,aAAa,CACjB,YAAY,EAAE,mBAAmB,EACjC,oBAAoB,CAAC,EAAE,uBAAuB,GAC7C,OAAO,CAAC,cAAc,CAAC;IAsB1B;;OAEG;IACH,IAAI,OAAO,IAAI,GAAG,CAEjB;CACF"}
|
|
@@ -33,8 +33,9 @@ export class AccountWallet {
|
|
|
33
33
|
/**
|
|
34
34
|
* Creates a payment payload from requirements.
|
|
35
35
|
* Only supports "exact" payment scheme.
|
|
36
|
+
* Note: serverAuthorization parameter is ignored for EOA wallets (only used by SmartAccountWallet)
|
|
36
37
|
*/
|
|
37
|
-
async createPayment(requirements) {
|
|
38
|
+
async createPayment(requirements, _serverAuthorization) {
|
|
38
39
|
if (requirements.scheme !== "exact") {
|
|
39
40
|
throw new WalletError(`Unsupported payment scheme: ${requirements.scheme}. AccountWallet only supports "exact".`);
|
|
40
41
|
}
|
|
@@ -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;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../../../src/x402/wallets/account/wallet.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAIjD,OAAO,EAAE,WAAW,EAAmB,MAAM,iBAAiB,CAAA;AAE9D;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,aAAa;IAChB,OAAO,CAAc;IAE7B,YAAY,OAAqB;QAC/B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,UAAe;QACnC,OAAO,IAAI,aAAa,CAAC,mB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|
|
@@ -18,6 +18,7 @@ export function createWalletFromConfig(config) {
|
|
|
18
18
|
sessionKeyPrivateKey: config.sessionKeyPrivateKey,
|
|
19
19
|
chainId: config.chainId,
|
|
20
20
|
validatorAddress: config.validatorAddress,
|
|
21
|
+
...(config.coSignerValidatorAddress != null && { coSignerValidatorAddress: config.coSignerValidatorAddress }),
|
|
21
22
|
});
|
|
22
23
|
}
|
|
23
24
|
//# sourceMappingURL=index.js.map
|
|
@@ -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;AA2BvF;;;;;;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,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,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,46 @@
|
|
|
1
|
+
import { type Address, type Hex, type TypedDataDefinition } from "viem";
|
|
2
|
+
import type { PaymentPayload, PaymentRequirements } from "x402/types";
|
|
3
|
+
import type { ServerAuthorizationData } from "../../types.ts";
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for creating a co-signed payment
|
|
6
|
+
*/
|
|
7
|
+
export interface CoSignedPaymentConfig {
|
|
8
|
+
/** Smart account address (payment sender) */
|
|
9
|
+
smartAccountAddress: Address;
|
|
10
|
+
/** Session key private key for signing */
|
|
11
|
+
sessionKeyPrivateKey: Hex;
|
|
12
|
+
/** Chain ID for the blockchain network */
|
|
13
|
+
chainId: number;
|
|
14
|
+
/** CoSignerValidator address */
|
|
15
|
+
coSignerValidatorAddress: Address;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Encode a co-signed ERC-1271 signature
|
|
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
|
|
30
|
+
*/
|
|
31
|
+
export declare function encodeCoSignedERC1271Signature(agentPrivateKey: Hex, typedDataParams: TypedDataDefinition, serverSignature: Hex, coSignerValidatorAddress: Address): Promise<Hex>;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a payment payload using server co-signature
|
|
34
|
+
*
|
|
35
|
+
* This is used for co-signed agent keys where the server provides the ERC-3009
|
|
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
|
|
44
|
+
*/
|
|
45
|
+
export declare function createCoSignedPayment(requirements: PaymentRequirements, config: CoSignedPaymentConfig, serverAuthorization: ServerAuthorizationData): Promise<PaymentPayload>;
|
|
46
|
+
//# sourceMappingURL=cosigned.d.ts.map
|
|
@@ -0,0 +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;AAE1G,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAGrE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAA;AAE7D;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,6CAA6C;IAC7C,mBAAmB,EAAE,OAAO,CAAA;IAC5B,0CAA0C;IAC1C,oBAAoB,EAAE,GAAG,CAAA;IACzB,0CAA0C;IAC1C,OAAO,EAAE,MAAM,CAAA;IACf,gCAAgC;IAChC,wBAAwB,EAAE,OAAO,CAAA;CAClC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,8BAA8B,CAClD,eAAe,EAAE,GAAG,EACpB,eAAe,EAAE,mBAAmB,EACpC,eAAe,EAAE,GAAG,EACpB,wBAAwB,EAAE,OAAO,GAChC,OAAO,CAAC,GAAG,CAAC,CAad;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,qBAAqB,CACzC,YAAY,EAAE,mBAAmB,EACjC,MAAM,EAAE,qBAAqB,EAC7B,mBAAmB,EAAE,uBAAuB,GAC3C,OAAO,CAAC,cAAc,CAAC,CA4DzB"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { encodeAbiParameters, encodePacked } from "viem";
|
|
2
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
3
|
+
import { TRANSFER_WITH_AUTHORIZATION_TYPE } from "../../../smart-account/eip712-types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Encode a co-signed ERC-1271 signature
|
|
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
|
|
17
|
+
*/
|
|
18
|
+
export async function encodeCoSignedERC1271Signature(agentPrivateKey, typedDataParams, serverSignature, coSignerValidatorAddress) {
|
|
19
|
+
// 1. Sign with agent key
|
|
20
|
+
const agentAccount = privateKeyToAccount(agentPrivateKey);
|
|
21
|
+
const agentSignature = await agentAccount.signTypedData(typedDataParams);
|
|
22
|
+
// 2. Combine signatures: abi.encode(bytes agentSig, bytes serverSig)
|
|
23
|
+
const combinedSignature = encodeAbiParameters([{ type: "bytes" }, { type: "bytes" }], [agentSignature, serverSignature]);
|
|
24
|
+
// 3. Encode for ERC-1271: encodePacked(address validator, bytes signature)
|
|
25
|
+
return encodePacked(["address", "bytes"], [coSignerValidatorAddress, combinedSignature]);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Creates a payment payload using server co-signature
|
|
29
|
+
*
|
|
30
|
+
* This is used for co-signed agent keys where the server provides the ERC-3009
|
|
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
|
|
39
|
+
*/
|
|
40
|
+
export async function createCoSignedPayment(requirements, config, serverAuthorization) {
|
|
41
|
+
const { authorizationData, serverSignature } = serverAuthorization;
|
|
42
|
+
// Get domain params from requirements.extra
|
|
43
|
+
const domainName = requirements.extra?.name;
|
|
44
|
+
const domainVersion = requirements.extra?.version;
|
|
45
|
+
if (!domainName || !domainVersion) {
|
|
46
|
+
throw new Error("requirements.extra must contain 'name' and 'version' for EIP-712 domain");
|
|
47
|
+
}
|
|
48
|
+
// Construct EIP-712 typed data from server-provided authorization data
|
|
49
|
+
const typedData = {
|
|
50
|
+
domain: {
|
|
51
|
+
name: domainName,
|
|
52
|
+
version: domainVersion,
|
|
53
|
+
chainId: config.chainId,
|
|
54
|
+
verifyingContract: requirements.asset,
|
|
55
|
+
},
|
|
56
|
+
types: {
|
|
57
|
+
TransferWithAuthorization: TRANSFER_WITH_AUTHORIZATION_TYPE,
|
|
58
|
+
},
|
|
59
|
+
primaryType: "TransferWithAuthorization",
|
|
60
|
+
message: {
|
|
61
|
+
from: authorizationData.from,
|
|
62
|
+
to: authorizationData.to,
|
|
63
|
+
value: BigInt(authorizationData.value),
|
|
64
|
+
validAfter: BigInt(authorizationData.validAfter),
|
|
65
|
+
validBefore: BigInt(authorizationData.validBefore),
|
|
66
|
+
nonce: authorizationData.nonce,
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
// Encode co-signed signature
|
|
70
|
+
const signature = await encodeCoSignedERC1271Signature(config.sessionKeyPrivateKey, typedData, serverSignature, config.coSignerValidatorAddress);
|
|
71
|
+
// Construct payment payload matching x402 exact scheme format
|
|
72
|
+
const paymentPayload = {
|
|
73
|
+
x402Version: 1,
|
|
74
|
+
scheme: "exact",
|
|
75
|
+
network: requirements.network,
|
|
76
|
+
payload: {
|
|
77
|
+
signature: signature,
|
|
78
|
+
authorization: {
|
|
79
|
+
from: authorizationData.from,
|
|
80
|
+
to: authorizationData.to,
|
|
81
|
+
value: authorizationData.value,
|
|
82
|
+
validAfter: authorizationData.validAfter,
|
|
83
|
+
validBefore: authorizationData.validBefore,
|
|
84
|
+
nonce: authorizationData.nonce,
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
return paymentPayload;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=cosigned.js.map
|
|
@@ -0,0 +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;AAGnD,OAAO,EAAE,gCAAgC,EAAE,MAAM,wCAAwC,CAAA;AAiBzF;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,8BAA8B,CAClD,eAAoB,EACpB,eAAoC,EACpC,eAAoB,EACpB,wBAAiC;IAEjC,yBAAyB;IACzB,MAAM,YAAY,GAAG,mBAAmB,CAAC,eAAe,CAAC,CAAA;IACzD,MAAM,cAAc,GAAG,MAAM,YA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AiB,CAAC,UAAU,CAAC;YAChD,WAAW,EAAE,MAAM,CAAC,iBAAiB,CAAC,WAAW,CAAC;YAClD,KAAK,EAAE,iBAAiB,CAAC,KAAY;SACtC;KACF,CAAA;IAED,6BAA6B;IAC7B,MAAM,SAAS,GAAG,MAAM,8BAA8B,CACpD,MAAM,CAAC,oBAAoB,EAC3B,SAAS,EACT,eAAsB,EACtB,MAAM,CAAC,wBAAwB,CAChC,CAAA;IAED,8DAA8D;IAC9D,MAAM,cAAc,GAAmB;QACrC,WAAW,EAAE,CAAC;QACd,MAAM,EAAE,OAAgB;QACxB,OAAO,EAAE,YAAY,CAAC,OAAO;QAC7B,OAAO,EAAE;YACP,SAAS,EAAE,SAAmB;YAC9B,aAAa,EAAE;gBACb,IAAI,EAAE,iBAAiB,CAAC,IAAI;gBAC5B,EAAE,EAAE,iBAAiB,CAAC,EAAE;gBACxB,KAAK,EAAE,iBAAiB,CAAC,KAAK;gBAC9B,UAAU,EAAE,iBAAiB,CAAC,UAAU;gBACxC,WAAW,EAAE,iBAAiB,CAAC,WAAW;gBAC1C,KAAK,EAAE,iBAAiB,CAAC,KAAK;aAC/B;SACF;KACF,CAAA;IAED,OAAO,cAAc,CAAA;AACvB,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Address, type Hex } from "viem";
|
|
2
2
|
import type { PaymentPayload, PaymentRequirements } from "x402/types";
|
|
3
|
+
import type { ServerAuthorizationData } from "../../types.ts";
|
|
3
4
|
import { type X402Wallet } from "../../wallet.ts";
|
|
4
5
|
/**
|
|
5
6
|
* Configuration for SmartAccountWallet
|
|
@@ -13,6 +14,8 @@ export interface SmartAccountConfig {
|
|
|
13
14
|
chainId: number;
|
|
14
15
|
/** OwnableValidator address (defaults to standard OwnableValidator) */
|
|
15
16
|
validatorAddress?: Address;
|
|
17
|
+
/** CoSignerValidator address (defaults to standard CoSignerValidator) */
|
|
18
|
+
coSignerValidatorAddress?: Address;
|
|
16
19
|
}
|
|
17
20
|
/**
|
|
18
21
|
* SmartAccountWallet - Smart account wallet implementation using ERC-1271
|
|
@@ -39,8 +42,12 @@ export declare class SmartAccountWallet implements X402Wallet {
|
|
|
39
42
|
/**
|
|
40
43
|
* Creates a payment payload from requirements.
|
|
41
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
|
|
42
49
|
*/
|
|
43
|
-
createPayment(requirements: PaymentRequirements): Promise<PaymentPayload>;
|
|
50
|
+
createPayment(requirements: PaymentRequirements, serverAuthorization?: ServerAuthorizationData): Promise<PaymentPayload>;
|
|
44
51
|
/**
|
|
45
52
|
* Returns the smart account address
|
|
46
53
|
*/
|
|
@@ -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;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAGrE,OAAO,EAAe,KAAK,UAAU,EAAE,MAAM,iBAAiB,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;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAGrE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAA;AAC7D,OAAO,EAAe,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAI9D;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,4BAA4B;IAC5B,mBAAmB,EAAE,OAAO,CAAA;IAC5B,0CAA0C;IAC1C,oBAAoB,EAAE,GAAG,CAAA;IACzB,0CAA0C;IAC1C,OAAO,EAAE,MAAM,CAAA;IACf,uEAAuE;IACvE,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,yEAAyE;IACzE,wBAAwB,CAAC,EAAE,OAAO,CAAA;CACnC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,kBAAmB,YAAW,UAAU;IACnD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuF;gBAElG,MAAM,EAAE,kBAAkB;IAStC;;;;;;;OAOG;IACG,aAAa,CACjB,YAAY,EAAE,mBAAmB,EACjC,mBAAmB,CAAC,EAAE,uBAAuB,GAC5C,OAAO,CAAC,cAAc,CAAC;IAuB1B;;OAEG;IACH,IAAI,OAAO,IAAI,OAAO,CAErB;CACF"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {} from "viem";
|
|
2
|
-
import { OWNABLE_VALIDATOR } from "../../../smart-account/constants.js";
|
|
2
|
+
import { COSIGNER_VALIDATOR, OWNABLE_VALIDATOR } from "../../../smart-account/constants.js";
|
|
3
3
|
import { WalletError } from "../../wallet.js";
|
|
4
|
+
import { createCoSignedPayment } from "./cosigned.js";
|
|
4
5
|
import { createExactPayment } from "./exact.js";
|
|
5
6
|
/**
|
|
6
7
|
* SmartAccountWallet - Smart account wallet implementation using ERC-1271
|
|
@@ -24,21 +25,31 @@ import { createExactPayment } from "./exact.js";
|
|
|
24
25
|
export class SmartAccountWallet {
|
|
25
26
|
config;
|
|
26
27
|
constructor(config) {
|
|
27
|
-
// Apply default validator
|
|
28
|
+
// Apply default validator addresses if not provided
|
|
28
29
|
this.config = {
|
|
29
30
|
...config,
|
|
30
31
|
validatorAddress: config.validatorAddress ?? OWNABLE_VALIDATOR,
|
|
32
|
+
coSignerValidatorAddress: config.coSignerValidatorAddress ?? COSIGNER_VALIDATOR,
|
|
31
33
|
};
|
|
32
34
|
}
|
|
33
35
|
/**
|
|
34
36
|
* Creates a payment payload from requirements.
|
|
35
37
|
* Only supports "exact" payment scheme with ERC-3009 authorizations.
|
|
38
|
+
*
|
|
39
|
+
* @param requirements Payment requirements from x402
|
|
40
|
+
* @param serverAuthorization Optional server co-signature data for co-signed keys
|
|
41
|
+
* @returns Payment payload ready to submit
|
|
36
42
|
*/
|
|
37
|
-
async createPayment(requirements) {
|
|
43
|
+
async createPayment(requirements, serverAuthorization) {
|
|
38
44
|
if (requirements.scheme !== "exact") {
|
|
39
45
|
throw new WalletError(`Unsupported payment scheme: ${requirements.scheme}. SmartAccountWallet only supports "exact".`);
|
|
40
46
|
}
|
|
41
47
|
try {
|
|
48
|
+
// If server authorization provided, use co-signed path
|
|
49
|
+
if (serverAuthorization) {
|
|
50
|
+
return await createCoSignedPayment(requirements, this.config, serverAuthorization);
|
|
51
|
+
}
|
|
52
|
+
// Otherwise use direct signing (full-access keys)
|
|
42
53
|
return await createExactPayment(requirements, this.config);
|
|
43
54
|
}
|
|
44
55
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../../../src/x402/wallets/smart-account/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,MAAM,MAAM,CAAA;AAG7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAA;
|
|
1
|
+
{"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../../../src/x402/wallets/smart-account/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,MAAM,MAAM,CAAA;AAG7C,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAA;AAE3F,OAAO,EAAE,WAAW,EAAmB,MAAM,iBAAiB,CAAA;AAC9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;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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.13",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/edgeandnode/ampersend-sdk.git"
|