@chipi-stack/core 0.2.1 → 0.3.1
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/README.md +9 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/signers/create-account.d.ts +21 -0
- package/dist/signers/create-account.d.ts.map +1 -0
- package/dist/signers/create-account.js +19 -0
- package/dist/signers/create-account.js.map +1 -0
- package/dist/signers/starknet-signer-adapter.d.ts +18 -0
- package/dist/signers/starknet-signer-adapter.d.ts.map +1 -0
- package/dist/signers/starknet-signer-adapter.js +26 -0
- package/dist/signers/starknet-signer-adapter.js.map +1 -0
- package/dist/transactions/tx-builder.d.ts +19 -1
- package/dist/transactions/tx-builder.d.ts.map +1 -1
- package/dist/transactions/tx-builder.js +24 -11
- package/dist/transactions/tx-builder.js.map +1 -1
- package/dist/x402/client.d.ts +112 -0
- package/dist/x402/client.d.ts.map +1 -0
- package/dist/x402/client.js +270 -0
- package/dist/x402/client.js.map +1 -0
- package/dist/x402/index.d.ts +2 -0
- package/dist/x402/index.d.ts.map +1 -0
- package/dist/x402/index.js +2 -0
- package/dist/x402/index.js.map +1 -0
- package/package.json +44 -7
package/README.md
CHANGED
|
@@ -82,6 +82,15 @@ const fee = await estimateFee(calls, account);
|
|
|
82
82
|
const check = await preflight(calls, account); // fee + balance check
|
|
83
83
|
```
|
|
84
84
|
|
|
85
|
+
## What you can ship
|
|
86
|
+
|
|
87
|
+
- **Gasless wallets for gaming and loyalty apps** — abstract away gas fees so users never touch crypto
|
|
88
|
+
- **Invisible signers for AI agents** — let autonomous agents sign and submit transactions
|
|
89
|
+
- **Multi-call DeFi transactions** — batch swaps, approvals, and transfers into a single execution
|
|
90
|
+
- **Custom payment flows for remittance platforms** — build cross-border payment rails on Starknet
|
|
91
|
+
|
|
92
|
+
Have an idea? [Tell us what you want to build](https://github.com/chipi-pay/build-with-chipi/issues/new)
|
|
93
|
+
|
|
85
94
|
## Documentation
|
|
86
95
|
|
|
87
96
|
Full docs at [docs.chipipay.com](https://docs.chipipay.com)
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
export { Amount, type TokenInfo } from "./tokens/amount.js";
|
|
2
2
|
export { Erc20 } from "./tokens/erc20.js";
|
|
3
3
|
export { TokenRegistry, type Network } from "./tokens/registry.js";
|
|
4
|
-
export { TxBuilder } from "./transactions/tx-builder.js";
|
|
4
|
+
export { TxBuilder, type TxBuilderOptions } from "./transactions/tx-builder.js";
|
|
5
5
|
export type { TransferTarget, PreflightResult } from "./transactions/types.js";
|
|
6
6
|
export { DirectSigner } from "./signers/direct-signer.js";
|
|
7
7
|
export { PasskeySigner } from "./signers/passkey-signer.js";
|
|
8
8
|
export { ExternalSigner } from "./signers/external-signer.js";
|
|
9
|
+
export { StarknetSignerAdapter } from "./signers/starknet-signer-adapter.js";
|
|
10
|
+
export { createAccount } from "./signers/create-account.js";
|
|
11
|
+
export type { CreateAccountOptions } from "./signers/create-account.js";
|
|
9
12
|
export type { SignerAdapter, SignResult } from "./signers/types.js";
|
|
10
13
|
export { estimateFee, preflight } from "./estimation/estimate-fee.js";
|
|
11
14
|
export type { FeeEstimate } from "./estimation/types.js";
|
|
15
|
+
export { X402Client, X402_DOMAIN, X402_TYPES, buildX402TypedData, type BuildX402SimpleParams, } from "./x402/index.js";
|
|
12
16
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,KAAK,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAGnE,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,KAAK,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAGnE,OAAO,EAAE,SAAS,EAAE,KAAK,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChF,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAG/E,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,YAAY,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACxE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGpE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACtE,YAAY,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGzD,OAAO,EACL,UAAU,EACV,WAAW,EACX,UAAU,EACV,kBAAkB,EAClB,KAAK,qBAAqB,GAC3B,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,10 @@ export { TxBuilder } from "./transactions/tx-builder.js";
|
|
|
8
8
|
export { DirectSigner } from "./signers/direct-signer.js";
|
|
9
9
|
export { PasskeySigner } from "./signers/passkey-signer.js";
|
|
10
10
|
export { ExternalSigner } from "./signers/external-signer.js";
|
|
11
|
+
export { StarknetSignerAdapter } from "./signers/starknet-signer-adapter.js";
|
|
12
|
+
export { createAccount } from "./signers/create-account.js";
|
|
11
13
|
// Estimation
|
|
12
14
|
export { estimateFee, preflight } from "./estimation/estimate-fee.js";
|
|
15
|
+
// x402 Payment Protocol
|
|
16
|
+
export { X402Client, X402_DOMAIN, X402_TYPES, buildX402TypedData, } from "./x402/index.js";
|
|
13
17
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,SAAS;AACT,OAAO,EAAE,MAAM,EAAkB,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAgB,MAAM,sBAAsB,CAAC;AAEnE,eAAe;AACf,OAAO,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,SAAS;AACT,OAAO,EAAE,MAAM,EAAkB,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAgB,MAAM,sBAAsB,CAAC;AAEnE,eAAe;AACf,OAAO,EAAE,SAAS,EAAyB,MAAM,8BAA8B,CAAC;AAGhF,UAAU;AACV,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAI5D,aAAa;AACb,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAGtE,wBAAwB;AACxB,OAAO,EACL,UAAU,EACV,WAAW,EACX,UAAU,EACV,kBAAkB,GAEnB,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Account } from "starknet";
|
|
2
|
+
import type { ProviderInterface, ProviderOptions, CairoVersion } from "starknet";
|
|
3
|
+
import type { SignerAdapter } from "./types.js";
|
|
4
|
+
export interface CreateAccountOptions {
|
|
5
|
+
/** Any SignerAdapter implementation (DirectSigner, PasskeySigner, ExternalSigner). */
|
|
6
|
+
signer: SignerAdapter;
|
|
7
|
+
/** Starknet provider or provider options. */
|
|
8
|
+
provider: ProviderOptions | ProviderInterface;
|
|
9
|
+
/** Override the account address (defaults to signer.getAccountAddress()). */
|
|
10
|
+
address?: string;
|
|
11
|
+
/** Cairo version for the account contract. */
|
|
12
|
+
cairoVersion?: CairoVersion;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Create a starknet.js Account from any SignerAdapter.
|
|
16
|
+
*
|
|
17
|
+
* Bridges the gap between SignerAdapter and starknet.js Account,
|
|
18
|
+
* so you can use the Account with TxBuilder or any starknet.js API.
|
|
19
|
+
*/
|
|
20
|
+
export declare function createAccount(opts: CreateAccountOptions): Promise<Account>;
|
|
21
|
+
//# sourceMappingURL=create-account.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-account.d.ts","sourceRoot":"","sources":["../../src/signers/create-account.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACjF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhD,MAAM,WAAW,oBAAoB;IACnC,sFAAsF;IACtF,MAAM,EAAE,aAAa,CAAC;IACtB,6CAA6C;IAC7C,QAAQ,EAAE,eAAe,GAAG,iBAAiB,CAAC;IAC9C,6EAA6E;IAC7E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,8CAA8C;IAC9C,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B;AAED;;;;;GAKG;AACH,wBAAsB,aAAa,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,OAAO,CAAC,CAShF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Account } from "starknet";
|
|
2
|
+
import { StarknetSignerAdapter } from "./starknet-signer-adapter.js";
|
|
3
|
+
/**
|
|
4
|
+
* Create a starknet.js Account from any SignerAdapter.
|
|
5
|
+
*
|
|
6
|
+
* Bridges the gap between SignerAdapter and starknet.js Account,
|
|
7
|
+
* so you can use the Account with TxBuilder or any starknet.js API.
|
|
8
|
+
*/
|
|
9
|
+
export async function createAccount(opts) {
|
|
10
|
+
const address = opts.address ?? await opts.signer.getAccountAddress();
|
|
11
|
+
const signer = new StarknetSignerAdapter(opts.signer);
|
|
12
|
+
return new Account({
|
|
13
|
+
provider: opts.provider,
|
|
14
|
+
address,
|
|
15
|
+
signer,
|
|
16
|
+
cairoVersion: opts.cairoVersion,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=create-account.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-account.js","sourceRoot":"","sources":["../../src/signers/create-account.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAGnC,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAarE;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,IAA0B;IAC5D,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE,CAAC;IACtE,MAAM,MAAM,GAAG,IAAI,qBAAqB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACtD,OAAO,IAAI,OAAO,CAAC;QACjB,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,OAAO;QACP,MAAM;QACN,YAAY,EAAE,IAAI,CAAC,YAAY;KAChC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Signer, type Signature } from "starknet";
|
|
2
|
+
import type { SignerAdapter } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Bridge between SignerAdapter and starknet.js Signer.
|
|
5
|
+
*
|
|
6
|
+
* Extends starknet.js `Signer`, overriding `signRaw()` to delegate to
|
|
7
|
+
* `SignerAdapter.sign()`. All hash computation is handled by starknet.js.
|
|
8
|
+
*
|
|
9
|
+
* This allows any SignerAdapter (DirectSigner, PasskeySigner, ExternalSigner)
|
|
10
|
+
* to be used where starknet.js expects a Signer instance (e.g., Account constructor).
|
|
11
|
+
*/
|
|
12
|
+
export declare class StarknetSignerAdapter extends Signer {
|
|
13
|
+
private readonly adapter;
|
|
14
|
+
constructor(adapter: SignerAdapter);
|
|
15
|
+
getPubKey(): Promise<string>;
|
|
16
|
+
protected signRaw(msgHash: string): Promise<Signature>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=starknet-signer-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"starknet-signer-adapter.d.ts","sourceRoot":"","sources":["../../src/signers/starknet-signer-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD;;;;;;;;GAQG;AACH,qBAAa,qBAAsB,SAAQ,MAAM;IAC/C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgB;gBAE5B,OAAO,EAAE,aAAa;IAOnB,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC;cAIlB,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;CAItE"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Signer } from "starknet";
|
|
2
|
+
/**
|
|
3
|
+
* Bridge between SignerAdapter and starknet.js Signer.
|
|
4
|
+
*
|
|
5
|
+
* Extends starknet.js `Signer`, overriding `signRaw()` to delegate to
|
|
6
|
+
* `SignerAdapter.sign()`. All hash computation is handled by starknet.js.
|
|
7
|
+
*
|
|
8
|
+
* This allows any SignerAdapter (DirectSigner, PasskeySigner, ExternalSigner)
|
|
9
|
+
* to be used where starknet.js expects a Signer instance (e.g., Account constructor).
|
|
10
|
+
*/
|
|
11
|
+
export class StarknetSignerAdapter extends Signer {
|
|
12
|
+
constructor(adapter) {
|
|
13
|
+
// Dummy private key — overridden methods never use it.
|
|
14
|
+
// Signer requires a key in its constructor, but we bypass all internal signing.
|
|
15
|
+
super("0x1");
|
|
16
|
+
this.adapter = adapter;
|
|
17
|
+
}
|
|
18
|
+
async getPubKey() {
|
|
19
|
+
return this.adapter.getPublicKey();
|
|
20
|
+
}
|
|
21
|
+
async signRaw(msgHash) {
|
|
22
|
+
const result = await this.adapter.sign(msgHash);
|
|
23
|
+
return [result.r, result.s];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=starknet-signer-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"starknet-signer-adapter.js","sourceRoot":"","sources":["../../src/signers/starknet-signer-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAkB,MAAM,UAAU,CAAC;AAGlD;;;;;;;;GAQG;AACH,MAAM,OAAO,qBAAsB,SAAQ,MAAM;IAG/C,YAAY,OAAsB;QAChC,uDAAuD;QACvD,gFAAgF;QAChF,KAAK,CAAC,KAAK,CAAC,CAAC;QACb,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAEQ,KAAK,CAAC,SAAS;QACtB,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC;IACrC,CAAC;IAEkB,KAAK,CAAC,OAAO,CAAC,OAAe;QAC9C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAChD,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IAC9B,CAAC;CACF"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Account, Call, InvokeFunctionResponse, EstimateFeeResponseOverhead } from "starknet";
|
|
2
|
+
import type { PaymasterAdapter } from "@chipi-stack/types";
|
|
2
3
|
import type { TransferTarget, PreflightResult } from "./types.js";
|
|
3
4
|
/**
|
|
4
5
|
* Fluent builder for batching Starknet calls.
|
|
@@ -10,11 +11,16 @@ import type { TransferTarget, PreflightResult } from "./types.js";
|
|
|
10
11
|
* .transfer(tokenAddr, [{ to: recipient, amount: 1000n }])
|
|
11
12
|
* .send();
|
|
12
13
|
*/
|
|
14
|
+
export interface TxBuilderOptions {
|
|
15
|
+
/** PaymasterAdapter for gasless transactions via sendSponsored(). */
|
|
16
|
+
paymaster?: PaymasterAdapter;
|
|
17
|
+
}
|
|
13
18
|
export declare class TxBuilder {
|
|
14
19
|
private readonly account;
|
|
20
|
+
private readonly paymaster?;
|
|
15
21
|
private readonly _calls;
|
|
16
22
|
private sent;
|
|
17
|
-
constructor(account: Account);
|
|
23
|
+
constructor(account: Account, opts?: TxBuilderOptions);
|
|
18
24
|
/** Returns a copy of the current call batch. */
|
|
19
25
|
calls(): Call[];
|
|
20
26
|
/**
|
|
@@ -41,6 +47,18 @@ export declare class TxBuilder {
|
|
|
41
47
|
* @throws If send() was already called
|
|
42
48
|
*/
|
|
43
49
|
send(): Promise<InvokeFunctionResponse>;
|
|
50
|
+
/**
|
|
51
|
+
* Execute via a paymaster (gasless). Requires a PaymasterAdapter.
|
|
52
|
+
*
|
|
53
|
+
* The paymaster handles: prepare typed data -> sign -> submit.
|
|
54
|
+
* For external wallets (Argent X, Braavos), signing triggers the wallet popup.
|
|
55
|
+
*
|
|
56
|
+
* @returns Transaction hash
|
|
57
|
+
* @throws If no paymaster was configured
|
|
58
|
+
* @throws If no calls have been added
|
|
59
|
+
* @throws If sendSponsored() or send() was already called
|
|
60
|
+
*/
|
|
61
|
+
sendSponsored(): Promise<string>;
|
|
44
62
|
/**
|
|
45
63
|
* Estimate fees for the current batch without executing.
|
|
46
64
|
* @throws If no calls have been added
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tx-builder.d.ts","sourceRoot":"","sources":["../../src/transactions/tx-builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,sBAAsB,EAAE,2BAA2B,EAAE,MAAM,UAAU,CAAC;AAEnG,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElE;;;;;;;;;GASG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;IAClC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAc;IACrC,OAAO,CAAC,IAAI,CAAS;gBAET,OAAO,EAAE,OAAO;
|
|
1
|
+
{"version":3,"file":"tx-builder.d.ts","sourceRoot":"","sources":["../../src/transactions/tx-builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,sBAAsB,EAAE,2BAA2B,EAAE,MAAM,UAAU,CAAC;AAEnG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElE;;;;;;;;;GASG;AACH,MAAM,WAAW,gBAAgB;IAC/B,qEAAqE;IACrE,SAAS,CAAC,EAAE,gBAAgB,CAAC;CAC9B;AAED,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;IAClC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAmB;IAC9C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAc;IACrC,OAAO,CAAC,IAAI,CAAS;gBAET,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,gBAAgB;IAKrD,gDAAgD;IAChD,KAAK,IAAI,IAAI,EAAE;IAIf;;;OAGG;IACH,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,GAAG,IAAI;IAM9B;;;;;OAKG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAW7D;;;;OAIG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,IAAI;IAaxD;;;;OAIG;IACG,IAAI,IAAI,OAAO,CAAC,sBAAsB,CAAC;IAQ7C;;;;;;;;;;OAUG;IACG,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAYtC;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,2BAA2B,CAAC;IAKzD;;;;OAIG;IACG,SAAS,IAAI,OAAO,CAAC,eAAe,CAAC;CAW5C"}
|
|
@@ -1,19 +1,10 @@
|
|
|
1
1
|
import { uint256 } from "starknet";
|
|
2
|
-
/**
|
|
3
|
-
* Fluent builder for batching Starknet calls.
|
|
4
|
-
* All calls execute atomically via Account.execute().
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* const result = await new TxBuilder(account)
|
|
8
|
-
* .approve(tokenAddr, spenderAddr, amount)
|
|
9
|
-
* .transfer(tokenAddr, [{ to: recipient, amount: 1000n }])
|
|
10
|
-
* .send();
|
|
11
|
-
*/
|
|
12
2
|
export class TxBuilder {
|
|
13
|
-
constructor(account) {
|
|
3
|
+
constructor(account, opts) {
|
|
14
4
|
this._calls = [];
|
|
15
5
|
this.sent = false;
|
|
16
6
|
this.account = account;
|
|
7
|
+
this.paymaster = opts?.paymaster;
|
|
17
8
|
}
|
|
18
9
|
/** Returns a copy of the current call batch. */
|
|
19
10
|
calls() {
|
|
@@ -77,6 +68,28 @@ export class TxBuilder {
|
|
|
77
68
|
const calls = [...this._calls];
|
|
78
69
|
return this.account.execute(calls);
|
|
79
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Execute via a paymaster (gasless). Requires a PaymasterAdapter.
|
|
73
|
+
*
|
|
74
|
+
* The paymaster handles: prepare typed data -> sign -> submit.
|
|
75
|
+
* For external wallets (Argent X, Braavos), signing triggers the wallet popup.
|
|
76
|
+
*
|
|
77
|
+
* @returns Transaction hash
|
|
78
|
+
* @throws If no paymaster was configured
|
|
79
|
+
* @throws If no calls have been added
|
|
80
|
+
* @throws If sendSponsored() or send() was already called
|
|
81
|
+
*/
|
|
82
|
+
async sendSponsored() {
|
|
83
|
+
if (!this.paymaster) {
|
|
84
|
+
throw new Error("No paymaster configured. Pass { paymaster } to TxBuilder constructor.");
|
|
85
|
+
}
|
|
86
|
+
if (this.sent)
|
|
87
|
+
throw new Error("TxBuilder already sent — create a new builder");
|
|
88
|
+
if (this._calls.length === 0)
|
|
89
|
+
throw new Error("No calls to execute");
|
|
90
|
+
this.sent = true;
|
|
91
|
+
return this.paymaster.execute({ account: this.account, calls: [...this._calls] });
|
|
92
|
+
}
|
|
80
93
|
/**
|
|
81
94
|
* Estimate fees for the current batch without executing.
|
|
82
95
|
* @throws If no calls have been added
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tx-builder.js","sourceRoot":"","sources":["../../src/transactions/tx-builder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"tx-builder.js","sourceRoot":"","sources":["../../src/transactions/tx-builder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAmB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,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACpF,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,WAAW;QACf,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;QACtE,OAAO,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAC1D,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,SAAS;QACb,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;QACvE,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,mBAAmB,CACnD,CAAC,EAAE,IAAI,EAAE,QAAiB,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,EACxD,EAAE,YAAY,EAAE,KAAK,EAAE,CACxB,CAAC;QACF,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACnC,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;QACpD,CAAC;QACD,OAAO,MAAM,CAAC,CAAC,CAA+B,CAAC;IACjD,CAAC;CACF"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { Account, TypedData } from "starknet";
|
|
2
|
+
import type { PaymentRequirement, PaymentPayload, X402ClientConfig } from "@chipi-stack/types";
|
|
3
|
+
/** SNIP-12 domain for x402 payments */
|
|
4
|
+
export declare const X402_DOMAIN: {
|
|
5
|
+
name: string;
|
|
6
|
+
version: string;
|
|
7
|
+
chainId: string;
|
|
8
|
+
};
|
|
9
|
+
/** SNIP-12 typed data structure for x402 payment */
|
|
10
|
+
export declare const X402_TYPES: {
|
|
11
|
+
StarknetDomain: {
|
|
12
|
+
name: string;
|
|
13
|
+
type: string;
|
|
14
|
+
}[];
|
|
15
|
+
Payment: {
|
|
16
|
+
name: string;
|
|
17
|
+
type: string;
|
|
18
|
+
}[];
|
|
19
|
+
};
|
|
20
|
+
/** Simple convenience params for buildX402TypedData */
|
|
21
|
+
export interface BuildX402SimpleParams {
|
|
22
|
+
/** Sender address */
|
|
23
|
+
from: string;
|
|
24
|
+
/** Recipient address */
|
|
25
|
+
recipient: string;
|
|
26
|
+
/** Amount in USDC base units (string) */
|
|
27
|
+
amount: string;
|
|
28
|
+
/** Nonce for replay protection */
|
|
29
|
+
nonce: string;
|
|
30
|
+
/** Seconds until expiry (default: 300) */
|
|
31
|
+
expiry?: number;
|
|
32
|
+
/** Asset address (default: USDC mainnet) */
|
|
33
|
+
asset?: string;
|
|
34
|
+
}
|
|
35
|
+
/** Full message params (original API) */
|
|
36
|
+
interface BuildX402FullMessage {
|
|
37
|
+
from_address: string;
|
|
38
|
+
to_address: string;
|
|
39
|
+
amount: string;
|
|
40
|
+
asset: string;
|
|
41
|
+
valid_until: string;
|
|
42
|
+
nonce: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Build the full SNIP-12 typed data object for an x402 payment.
|
|
46
|
+
* Centralises the structure so client, facilitator, and React hook stay in sync.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* // Full params (original)
|
|
51
|
+
* buildX402TypedData({ from_address, to_address, amount, asset, valid_until, nonce })
|
|
52
|
+
*
|
|
53
|
+
* // Simple convenience params
|
|
54
|
+
* buildX402TypedData({ from: sender, recipient, amount, nonce, expiry: 300 })
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare function buildX402TypedData(message: BuildX402FullMessage | BuildX402SimpleParams): TypedData;
|
|
58
|
+
/**
|
|
59
|
+
* Minimal fetch-compatible interfaces.
|
|
60
|
+
* These mirror the standard Fetch API but allow the client to work
|
|
61
|
+
* in both browser and Node.js (18+) environments without requiring DOM lib.
|
|
62
|
+
*/
|
|
63
|
+
interface FetchResponse {
|
|
64
|
+
status: number;
|
|
65
|
+
headers: {
|
|
66
|
+
get(name: string): string | null;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* x402 payment client for Starknet.
|
|
71
|
+
*
|
|
72
|
+
* Wraps fetch calls with automatic HTTP 402 payment handling.
|
|
73
|
+
* When a server returns 402 Payment Required, the client:
|
|
74
|
+
* 1. Parses the payment requirement from the response header
|
|
75
|
+
* 2. Validates against configured limits (max amount, allowed recipients)
|
|
76
|
+
* 3. Signs a SNIP-12 typed data payment message
|
|
77
|
+
* 4. Retries the request with the signed payment in the X-PAYMENT header
|
|
78
|
+
*
|
|
79
|
+
* Works with any Starknet Account (DirectSigner, passkey, session key, external wallet).
|
|
80
|
+
* When used with a session key account, payments are fully automatic (no user interaction).
|
|
81
|
+
*/
|
|
82
|
+
export declare class X402Client {
|
|
83
|
+
private readonly account;
|
|
84
|
+
private readonly config;
|
|
85
|
+
private readonly fetchFn;
|
|
86
|
+
constructor(account: Account, config?: X402ClientConfig);
|
|
87
|
+
/**
|
|
88
|
+
* Wrap a fetch call with x402 payment handling.
|
|
89
|
+
* If the server returns 402, automatically sign payment and retry.
|
|
90
|
+
*/
|
|
91
|
+
fetch(url: string, init?: Record<string, any>): Promise<FetchResponse>;
|
|
92
|
+
/**
|
|
93
|
+
* Parse PAYMENT-REQUIRED header from 402 response.
|
|
94
|
+
*/
|
|
95
|
+
parsePaymentRequired(response: FetchResponse): PaymentRequirement;
|
|
96
|
+
/**
|
|
97
|
+
* Validate payment requirement against client configuration limits.
|
|
98
|
+
* Throws if the payment would exceed maxPaymentAmount or recipient is not whitelisted.
|
|
99
|
+
*/
|
|
100
|
+
validateRequirement(requirement: PaymentRequirement): void;
|
|
101
|
+
/**
|
|
102
|
+
* Sign a SNIP-12 typed data payment message for the given requirement.
|
|
103
|
+
* Returns a PaymentPayload ready to be sent as the X-PAYMENT header.
|
|
104
|
+
*/
|
|
105
|
+
signPayment(requirement: PaymentRequirement): Promise<PaymentPayload>;
|
|
106
|
+
/**
|
|
107
|
+
* Retry the original request with the X-PAYMENT header containing the signed payment.
|
|
108
|
+
*/
|
|
109
|
+
private retryWithPayment;
|
|
110
|
+
}
|
|
111
|
+
export {};
|
|
112
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/x402/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACnD,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAc/F,uCAAuC;AACvC,eAAO,MAAM,WAAW;;;;CAIvB,CAAC;AAEF,oDAAoD;AACpD,eAAO,MAAM,UAAU;;;;;;;;;CActB,CAAC;AAEF,uDAAuD;AACvD,MAAM,WAAW,qBAAqB;IACpC,qBAAqB;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,wBAAwB;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,yCAAyC;IACzC,MAAM,EAAE,MAAM,CAAC;IACf,kCAAkC;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,0CAA0C;IAC1C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4CAA4C;IAC5C,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,yCAAyC;AACzC,UAAU,oBAAoB;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;CACf;AAQD;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,oBAAoB,GAAG,qBAAqB,GACpD,SAAS,CA0BX;AAED;;;;GAIG;AACH,UAAU,aAAa;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE;QAAE,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;CAC/C;AAQD;;;;;;;;;;;;GAYG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;IAClC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoE;IAC3F,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;gBAEtB,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,gBAAgB;IAUvD;;;OAGG;IACG,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC;IAa5E;;OAEG;IACH,oBAAoB,CAAC,QAAQ,EAAE,aAAa,GAAG,kBAAkB;IA+DjE;;;OAGG;IACH,mBAAmB,CAAC,WAAW,EAAE,kBAAkB,GAAG,IAAI;IAsC1D;;;OAGG;IACG,WAAW,CAAC,WAAW,EAAE,kBAAkB,GAAG,OAAO,CAAC,cAAc,CAAC;IAkC3E;;OAEG;YACW,gBAAgB;CAgB/B"}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
/** USDC native address on Starknet mainnet */
|
|
2
|
+
const USDC_MAINNET = "0x033068F6539f8e6e6b131e6B2B814e6c34A5224bC66947c47DaB9dFeE93b35fb";
|
|
3
|
+
/** USDC decimals */
|
|
4
|
+
const USDC_DECIMALS = 6;
|
|
5
|
+
/** Header name for x402 payment requirement */
|
|
6
|
+
const PAYMENT_REQUIRED_HEADER = "payment-required";
|
|
7
|
+
/** Default header name for sending payment */
|
|
8
|
+
const DEFAULT_PAYMENT_HEADER = "X-PAYMENT";
|
|
9
|
+
/** SNIP-12 domain for x402 payments */
|
|
10
|
+
export const X402_DOMAIN = {
|
|
11
|
+
name: "x402-starknet",
|
|
12
|
+
version: "1",
|
|
13
|
+
chainId: "SN_MAIN",
|
|
14
|
+
};
|
|
15
|
+
/** SNIP-12 typed data structure for x402 payment */
|
|
16
|
+
export const X402_TYPES = {
|
|
17
|
+
StarknetDomain: [
|
|
18
|
+
{ name: "name", type: "shortstring" },
|
|
19
|
+
{ name: "version", type: "shortstring" },
|
|
20
|
+
{ name: "chainId", type: "shortstring" },
|
|
21
|
+
],
|
|
22
|
+
Payment: [
|
|
23
|
+
{ name: "from_address", type: "ContractAddress" },
|
|
24
|
+
{ name: "to_address", type: "ContractAddress" },
|
|
25
|
+
{ name: "amount", type: "u256" },
|
|
26
|
+
{ name: "asset", type: "ContractAddress" },
|
|
27
|
+
{ name: "valid_until", type: "u128" },
|
|
28
|
+
{ name: "nonce", type: "felt" },
|
|
29
|
+
],
|
|
30
|
+
};
|
|
31
|
+
function isSimpleParams(params) {
|
|
32
|
+
return "recipient" in params && "from" in params;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Build the full SNIP-12 typed data object for an x402 payment.
|
|
36
|
+
* Centralises the structure so client, facilitator, and React hook stay in sync.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* // Full params (original)
|
|
41
|
+
* buildX402TypedData({ from_address, to_address, amount, asset, valid_until, nonce })
|
|
42
|
+
*
|
|
43
|
+
* // Simple convenience params
|
|
44
|
+
* buildX402TypedData({ from: sender, recipient, amount, nonce, expiry: 300 })
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export function buildX402TypedData(message) {
|
|
48
|
+
let resolved;
|
|
49
|
+
if (isSimpleParams(message)) {
|
|
50
|
+
const validUntil = Math.floor(Date.now() / 1000) + (message.expiry ?? 300);
|
|
51
|
+
resolved = {
|
|
52
|
+
from_address: message.from,
|
|
53
|
+
to_address: message.recipient,
|
|
54
|
+
amount: message.amount,
|
|
55
|
+
asset: message.asset ?? USDC_MAINNET,
|
|
56
|
+
valid_until: String(validUntil),
|
|
57
|
+
nonce: message.nonce,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
resolved = message;
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
types: X402_TYPES,
|
|
65
|
+
primaryType: "Payment",
|
|
66
|
+
domain: X402_DOMAIN,
|
|
67
|
+
message: {
|
|
68
|
+
...resolved,
|
|
69
|
+
amount: { low: resolved.amount, high: "0" },
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* x402 payment client for Starknet.
|
|
75
|
+
*
|
|
76
|
+
* Wraps fetch calls with automatic HTTP 402 payment handling.
|
|
77
|
+
* When a server returns 402 Payment Required, the client:
|
|
78
|
+
* 1. Parses the payment requirement from the response header
|
|
79
|
+
* 2. Validates against configured limits (max amount, allowed recipients)
|
|
80
|
+
* 3. Signs a SNIP-12 typed data payment message
|
|
81
|
+
* 4. Retries the request with the signed payment in the X-PAYMENT header
|
|
82
|
+
*
|
|
83
|
+
* Works with any Starknet Account (DirectSigner, passkey, session key, external wallet).
|
|
84
|
+
* When used with a session key account, payments are fully automatic (no user interaction).
|
|
85
|
+
*/
|
|
86
|
+
export class X402Client {
|
|
87
|
+
constructor(account, config) {
|
|
88
|
+
this.account = account;
|
|
89
|
+
this.config = {
|
|
90
|
+
headerName: DEFAULT_PAYMENT_HEADER,
|
|
91
|
+
...config,
|
|
92
|
+
};
|
|
93
|
+
// Use global fetch (available in Node 18+ and browsers)
|
|
94
|
+
this.fetchFn = globalThis.fetch;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Wrap a fetch call with x402 payment handling.
|
|
98
|
+
* If the server returns 402, automatically sign payment and retry.
|
|
99
|
+
*/
|
|
100
|
+
async fetch(url, init) {
|
|
101
|
+
const response = await this.fetchFn(url, init);
|
|
102
|
+
if (response.status !== 402) {
|
|
103
|
+
return response;
|
|
104
|
+
}
|
|
105
|
+
const requirement = this.parsePaymentRequired(response);
|
|
106
|
+
this.validateRequirement(requirement);
|
|
107
|
+
const payment = await this.signPayment(requirement);
|
|
108
|
+
return this.retryWithPayment(url, init, payment);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Parse PAYMENT-REQUIRED header from 402 response.
|
|
112
|
+
*/
|
|
113
|
+
parsePaymentRequired(response) {
|
|
114
|
+
const headerValue = response.headers.get(PAYMENT_REQUIRED_HEADER);
|
|
115
|
+
if (!headerValue) {
|
|
116
|
+
throw new Error("Server returned 402 but no PAYMENT-REQUIRED header. " +
|
|
117
|
+
"The server may not support x402 or is misconfigured.");
|
|
118
|
+
}
|
|
119
|
+
let requirement;
|
|
120
|
+
try {
|
|
121
|
+
requirement = JSON.parse(headerValue);
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
throw new Error(`Malformed PAYMENT-REQUIRED header: invalid JSON. Got: "${headerValue.slice(0, 100)}"`);
|
|
125
|
+
}
|
|
126
|
+
if (!requirement.scheme || !requirement.network || !requirement.maxAmountRequired) {
|
|
127
|
+
throw new Error("Invalid payment requirement: missing required fields (scheme, network, maxAmountRequired)");
|
|
128
|
+
}
|
|
129
|
+
if (requirement.scheme !== "exact") {
|
|
130
|
+
throw new Error(`Unsupported payment scheme: "${requirement.scheme}". Only "exact" is supported.`);
|
|
131
|
+
}
|
|
132
|
+
if (requirement.network !== "starknet-mainnet") {
|
|
133
|
+
throw new Error(`Unsupported network: "${requirement.network}". Only "starknet-mainnet" is supported.`);
|
|
134
|
+
}
|
|
135
|
+
if (!requirement.payTo) {
|
|
136
|
+
throw new Error("Invalid payment requirement: missing payTo address");
|
|
137
|
+
}
|
|
138
|
+
if (!requirement.asset) {
|
|
139
|
+
throw new Error("Invalid payment requirement: missing asset address");
|
|
140
|
+
}
|
|
141
|
+
if (typeof requirement.maxTimeoutSeconds !== "number" || requirement.maxTimeoutSeconds <= 0) {
|
|
142
|
+
throw new Error("Invalid payment requirement: maxTimeoutSeconds must be a positive number");
|
|
143
|
+
}
|
|
144
|
+
try {
|
|
145
|
+
const parsedAmount = BigInt(requirement.maxAmountRequired);
|
|
146
|
+
if (parsedAmount <= 0n) {
|
|
147
|
+
throw new Error("non-positive");
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
throw new Error(`Invalid payment requirement: maxAmountRequired must be a positive integer, got "${requirement.maxAmountRequired}"`);
|
|
152
|
+
}
|
|
153
|
+
return requirement;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Validate payment requirement against client configuration limits.
|
|
157
|
+
* Throws if the payment would exceed maxPaymentAmount or recipient is not whitelisted.
|
|
158
|
+
*/
|
|
159
|
+
validateRequirement(requirement) {
|
|
160
|
+
// Validate payment amount
|
|
161
|
+
if (this.config.maxPaymentAmount) {
|
|
162
|
+
const maxBaseUnits = humanUsdcToBaseUnits(this.config.maxPaymentAmount, USDC_DECIMALS);
|
|
163
|
+
const requiredAmount = BigInt(requirement.maxAmountRequired);
|
|
164
|
+
if (requiredAmount > maxBaseUnits) {
|
|
165
|
+
const requiredHuman = (Number(requiredAmount) / 10 ** USDC_DECIMALS).toFixed(USDC_DECIMALS);
|
|
166
|
+
throw new Error(`Payment amount ${requiredHuman} USDC exceeds maximum allowed ${this.config.maxPaymentAmount} USDC`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
// Validate recipient whitelist
|
|
170
|
+
if (this.config.allowedRecipients && this.config.allowedRecipients.length > 0) {
|
|
171
|
+
const normalizedPayTo = requirement.payTo.toLowerCase();
|
|
172
|
+
const isAllowed = this.config.allowedRecipients.some((addr) => addr.toLowerCase() === normalizedPayTo);
|
|
173
|
+
if (!isAllowed) {
|
|
174
|
+
throw new Error(`Recipient ${requirement.payTo} is not in the allowed recipients list`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
// Validate asset is USDC
|
|
178
|
+
const normalizedAsset = requirement.asset.toLowerCase().replace(/^0x0+/, "0x");
|
|
179
|
+
const normalizedUsdc = USDC_MAINNET.toLowerCase().replace(/^0x0+/, "0x");
|
|
180
|
+
if (normalizedAsset !== normalizedUsdc) {
|
|
181
|
+
throw new Error(`Unsupported asset: ${requirement.asset}. Only USDC (${USDC_MAINNET}) is supported.`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Sign a SNIP-12 typed data payment message for the given requirement.
|
|
186
|
+
* Returns a PaymentPayload ready to be sent as the X-PAYMENT header.
|
|
187
|
+
*/
|
|
188
|
+
async signPayment(requirement) {
|
|
189
|
+
const nonce = generateNonce();
|
|
190
|
+
const validUntil = Math.floor(Date.now() / 1000) + requirement.maxTimeoutSeconds;
|
|
191
|
+
const typedData = buildX402TypedData({
|
|
192
|
+
from_address: this.account.address,
|
|
193
|
+
to_address: requirement.payTo,
|
|
194
|
+
amount: requirement.maxAmountRequired,
|
|
195
|
+
asset: requirement.asset,
|
|
196
|
+
valid_until: String(validUntil),
|
|
197
|
+
nonce,
|
|
198
|
+
});
|
|
199
|
+
const signature = await this.account.signMessage(typedData);
|
|
200
|
+
// Normalize signature to { r, s } format
|
|
201
|
+
const normalizedSig = normalizeX402Signature(signature);
|
|
202
|
+
return {
|
|
203
|
+
x402Version: 1,
|
|
204
|
+
scheme: "exact",
|
|
205
|
+
network: "starknet-mainnet",
|
|
206
|
+
payload: {
|
|
207
|
+
signature: normalizedSig,
|
|
208
|
+
fromAddress: this.account.address,
|
|
209
|
+
toAddress: requirement.payTo,
|
|
210
|
+
amount: requirement.maxAmountRequired,
|
|
211
|
+
asset: requirement.asset,
|
|
212
|
+
validUntil,
|
|
213
|
+
nonce,
|
|
214
|
+
},
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Retry the original request with the X-PAYMENT header containing the signed payment.
|
|
219
|
+
*/
|
|
220
|
+
async retryWithPayment(url, init, payment) {
|
|
221
|
+
const existingHeaders = init?.headers ?? {};
|
|
222
|
+
const headers = {
|
|
223
|
+
...existingHeaders,
|
|
224
|
+
[this.config.headerName]: JSON.stringify(payment),
|
|
225
|
+
};
|
|
226
|
+
return this.fetchFn(url, {
|
|
227
|
+
...init,
|
|
228
|
+
headers,
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Convert human-readable USDC amount to base units using string arithmetic (no float).
|
|
234
|
+
*/
|
|
235
|
+
function humanUsdcToBaseUnits(amount, decimals) {
|
|
236
|
+
const [whole, frac = ""] = amount.trim().split(".");
|
|
237
|
+
const fracPadded = (frac + "0".repeat(decimals)).slice(0, decimals);
|
|
238
|
+
return BigInt((whole || "0") + fracPadded);
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Generate a unique nonce for replay protection.
|
|
242
|
+
* Uses crypto.randomUUID when available, falls back to timestamp + random.
|
|
243
|
+
*/
|
|
244
|
+
function generateNonce() {
|
|
245
|
+
if (typeof globalThis.crypto?.randomUUID === "function") {
|
|
246
|
+
return globalThis.crypto.randomUUID();
|
|
247
|
+
}
|
|
248
|
+
return `${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Normalize signature from account.signMessage() to { r, s } string format.
|
|
252
|
+
* Handles WeierstrassSignatureType ({r, s} as bigint) and ArraySignatureType ([r, s]).
|
|
253
|
+
*/
|
|
254
|
+
function normalizeX402Signature(signature) {
|
|
255
|
+
if (Array.isArray(signature)) {
|
|
256
|
+
if (signature.length < 2) {
|
|
257
|
+
throw new Error(`Array signature must have at least 2 elements, got ${signature.length}`);
|
|
258
|
+
}
|
|
259
|
+
return { r: String(signature[0]), s: String(signature[1]) };
|
|
260
|
+
}
|
|
261
|
+
if (signature && typeof signature === "object" && "r" in signature && "s" in signature) {
|
|
262
|
+
const sig = signature;
|
|
263
|
+
if (sig.r == null || sig.s == null) {
|
|
264
|
+
throw new Error("Invalid signature object: r and s must be non-null");
|
|
265
|
+
}
|
|
266
|
+
return { r: String(sig.r), s: String(sig.s) };
|
|
267
|
+
}
|
|
268
|
+
throw new Error("Unrecognized signature format from account.signMessage()");
|
|
269
|
+
}
|
|
270
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/x402/client.ts"],"names":[],"mappings":"AAGA,8CAA8C;AAC9C,MAAM,YAAY,GAAG,oEAAoE,CAAC;AAE1F,oBAAoB;AACpB,MAAM,aAAa,GAAG,CAAC,CAAC;AAExB,+CAA+C;AAC/C,MAAM,uBAAuB,GAAG,kBAAkB,CAAC;AAEnD,8CAA8C;AAC9C,MAAM,sBAAsB,GAAG,WAAW,CAAC;AAE3C,uCAAuC;AACvC,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,IAAI,EAAE,eAAe;IACrB,OAAO,EAAE,GAAG;IACZ,OAAO,EAAE,SAAS;CACnB,CAAC;AAEF,oDAAoD;AACpD,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,cAAc,EAAE;QACd,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE;QACrC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,aAAa,EAAE;QACxC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,aAAa,EAAE;KACzC;IACD,OAAO,EAAE;QACP,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,iBAAiB,EAAE;QACjD,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,iBAAiB,EAAE;QAC/C,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE;QAChC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,iBAAiB,EAAE;QAC1C,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAA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AC,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC9D,CAAC;IAED,IAAI,SAAS,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,GAAG,IAAI,SAAS,IAAI,GAAG,IAAI,SAAS,EAAE,CAAC;QACvF,MAAM,GAAG,GAAG,SAAuC,CAAC;QACpD,IAAI,GAAG,CAAC,CAAC,IAAI,IAAI,IAAI,GAAG,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC;YACnC,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;QACxE,CAAC;QACD,OAAO,EAAE,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IAChD,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;AAC9E,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/x402/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,WAAW,EACX,UAAU,EACV,kBAAkB,EAClB,KAAK,qBAAqB,GAC3B,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/x402/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,WAAW,EACX,UAAU,EACV,kBAAkB,GAEnB,MAAM,aAAa,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chipi-stack/core",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.3.1",
|
|
4
|
+
"description": "Gasless wallet primitives for Starknet — TxBuilder, SignerAdapter, TokenRegistry, and account abstraction core",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -14,24 +14,61 @@
|
|
|
14
14
|
"files": [
|
|
15
15
|
"dist"
|
|
16
16
|
],
|
|
17
|
+
"keywords": [
|
|
18
|
+
"chipi",
|
|
19
|
+
"chipi-pay",
|
|
20
|
+
"chipi-stack",
|
|
21
|
+
"starknet",
|
|
22
|
+
"starkware",
|
|
23
|
+
"ethereum",
|
|
24
|
+
"l2",
|
|
25
|
+
"web3",
|
|
26
|
+
"blockchain",
|
|
27
|
+
"wallet",
|
|
28
|
+
"smart-account",
|
|
29
|
+
"account-abstraction",
|
|
30
|
+
"gasless",
|
|
31
|
+
"payments",
|
|
32
|
+
"crypto-payments",
|
|
33
|
+
"stablecoin-payments",
|
|
34
|
+
"stablecoins",
|
|
35
|
+
"usdc",
|
|
36
|
+
"sdk",
|
|
37
|
+
"typescript",
|
|
38
|
+
"ai-payments",
|
|
39
|
+
"agent-payments"
|
|
40
|
+
],
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "git+https://github.com/chipi-pay/build-with-chipi.git"
|
|
44
|
+
},
|
|
45
|
+
"homepage": "https://docs.chipipay.com",
|
|
46
|
+
"bugs": {
|
|
47
|
+
"url": "https://github.com/chipi-pay/build-with-chipi/issues"
|
|
48
|
+
},
|
|
49
|
+
"author": {
|
|
50
|
+
"name": "Chipi Pay",
|
|
51
|
+
"email": "carlos@chipipay.com",
|
|
52
|
+
"url": "https://chipipay.com"
|
|
53
|
+
},
|
|
54
|
+
"license": "MIT",
|
|
17
55
|
"dependencies": {
|
|
18
|
-
"@chipi-stack/types": "^14.
|
|
56
|
+
"@chipi-stack/types": "^14.1.1"
|
|
19
57
|
},
|
|
20
58
|
"devDependencies": {
|
|
21
59
|
"typescript": "^5.7.3",
|
|
22
60
|
"vitest": "^3.2.4",
|
|
23
|
-
"starknet": ">=
|
|
61
|
+
"starknet": ">=9.2.1"
|
|
24
62
|
},
|
|
25
63
|
"peerDependencies": {
|
|
26
|
-
"starknet": ">=
|
|
64
|
+
"starknet": ">=9.2.1"
|
|
27
65
|
},
|
|
28
66
|
"engines": {
|
|
29
|
-
"node": ">=
|
|
67
|
+
"node": ">=20.19.0"
|
|
30
68
|
},
|
|
31
69
|
"publishConfig": {
|
|
32
70
|
"access": "public"
|
|
33
71
|
},
|
|
34
|
-
"license": "MIT",
|
|
35
72
|
"scripts": {
|
|
36
73
|
"build": "tsc",
|
|
37
74
|
"test": "vitest run",
|