@three-ws/x402-modal 0.2.0 → 0.2.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/CHANGELOG.md +24 -0
- package/CONTRIBUTING.md +92 -0
- package/LICENSE +38 -180
- package/README.md +541 -175
- package/TUTORIAL.md +1 -1
- package/dist/x402-modal.mjs +12 -9
- package/dist/x402-modal.mjs.map +2 -2
- package/dist/x402.global.js +10 -9
- package/dist/x402.global.js.map +2 -2
- package/docs/BACKEND.md +2 -1
- package/docs/CONFIGURATION.md +20 -6
- package/docs/EXAMPLES.md +279 -0
- package/examples/index.html +119 -0
- package/examples/server.mjs +144 -0
- package/package.json +11 -9
- package/src/x402-modal.js +20 -15
- package/types/index.d.ts +7 -3
package/src/x402-modal.js
CHANGED
|
@@ -40,10 +40,10 @@ import {
|
|
|
40
40
|
const VERSION = '0.2.0';
|
|
41
41
|
|
|
42
42
|
// ─────────────────────────────────────────────────────────── configuration ───
|
|
43
|
-
// Everything the host wants to brand or repoint lives here.
|
|
44
|
-
//
|
|
45
|
-
//
|
|
46
|
-
// `pay({ ... })` options (which always win over the global config).
|
|
43
|
+
// Everything the host wants to brand or repoint lives here. The defaults are
|
|
44
|
+
// vendor-neutral: no footer attribution and no builder-code echo until the host
|
|
45
|
+
// opts in. A deployment supplies its own branding with `configure()` (global)
|
|
46
|
+
// or per-call `pay({ ... })` options (which always win over the global config).
|
|
47
47
|
|
|
48
48
|
const DEFAULTS = {
|
|
49
49
|
// Origin that serves the Solana `prepare` / `encode` checkout helpers
|
|
@@ -51,12 +51,13 @@ const DEFAULTS = {
|
|
|
51
51
|
// payment path uses these — the EVM/EIP-3009 path is fully client-side and
|
|
52
52
|
// needs no backend. `null` ⇒ resolve from the script's own origin at runtime.
|
|
53
53
|
apiOrigin: null,
|
|
54
|
-
// Footer attribution shown at the bottom of the modal.
|
|
55
|
-
|
|
54
|
+
// Footer attribution shown at the bottom of the modal. `null` ⇒ the footer
|
|
55
|
+
// link is hidden until a host sets `{ label, href? }`.
|
|
56
|
+
brand: null,
|
|
56
57
|
// ERC-8021 builder-code self-attribution echoed back when the 402 challenge
|
|
57
58
|
// declares a builder code. `wallet` = your wallet code, `service` = your
|
|
58
|
-
// integration code.
|
|
59
|
-
builderCode:
|
|
59
|
+
// integration code. `null` ⇒ no self-attribution unless a host opts in.
|
|
60
|
+
builderCode: null,
|
|
60
61
|
// CDN modules dynamic-imported on demand. Override to self-host / satisfy a
|
|
61
62
|
// strict Content-Security-Policy.
|
|
62
63
|
solanaWeb3Url: 'https://esm.sh/@solana/web3.js@1.95.3?bundle',
|
|
@@ -65,7 +66,7 @@ const DEFAULTS = {
|
|
|
65
66
|
|
|
66
67
|
const config = {
|
|
67
68
|
apiOrigin: DEFAULTS.apiOrigin,
|
|
68
|
-
brand: { ...DEFAULTS.brand },
|
|
69
|
+
brand: DEFAULTS.brand ? { ...DEFAULTS.brand } : null,
|
|
69
70
|
builderCode: DEFAULTS.builderCode ? { ...DEFAULTS.builderCode } : null,
|
|
70
71
|
solanaWeb3Url: DEFAULTS.solanaWeb3Url,
|
|
71
72
|
nobleHashesUrl: DEFAULTS.nobleHashesUrl,
|
|
@@ -90,7 +91,8 @@ function resolveScriptOrigin() {
|
|
|
90
91
|
export function configure(opts = {}) {
|
|
91
92
|
if (!opts || typeof opts !== 'object') return getConfig();
|
|
92
93
|
if (opts.apiOrigin !== undefined) config.apiOrigin = opts.apiOrigin;
|
|
93
|
-
if (opts.brand) config.brand =
|
|
94
|
+
if (opts.brand === null) config.brand = null;
|
|
95
|
+
else if (opts.brand) config.brand = { ...(config.brand || {}), ...opts.brand };
|
|
94
96
|
if (opts.builderCode === null) config.builderCode = null;
|
|
95
97
|
else if (opts.builderCode) config.builderCode = { ...(config.builderCode || {}), ...opts.builderCode };
|
|
96
98
|
if (opts.solanaWeb3Url) config.solanaWeb3Url = opts.solanaWeb3Url;
|
|
@@ -101,7 +103,7 @@ export function configure(opts = {}) {
|
|
|
101
103
|
export function getConfig() {
|
|
102
104
|
return {
|
|
103
105
|
apiOrigin: config.apiOrigin,
|
|
104
|
-
brand: { ...config.brand },
|
|
106
|
+
brand: config.brand ? { ...config.brand } : null,
|
|
105
107
|
builderCode: config.builderCode ? { ...config.builderCode } : null,
|
|
106
108
|
solanaWeb3Url: config.solanaWeb3Url,
|
|
107
109
|
nobleHashesUrl: config.nobleHashesUrl,
|
|
@@ -840,12 +842,15 @@ export class CheckoutModal {
|
|
|
840
842
|
this.siwx = extractSiwxExtension(challenge);
|
|
841
843
|
this.payFlowOverride = false;
|
|
842
844
|
this.siwxFallbackNotice = null;
|
|
843
|
-
//
|
|
844
|
-
//
|
|
845
|
+
// Solana-first platform default: select the Solana accept by default
|
|
846
|
+
// whenever one is offered, regardless of which wallet is detected —
|
|
847
|
+
// renderConnect() still shows both wallet buttons (Solana listed
|
|
848
|
+
// first), so EVM users simply click the EVM option. Falls back to the
|
|
849
|
+
// first EIP-3009 EVM entry (skipping Permit2 siblings the modal can't
|
|
850
|
+
// sign for), then the first accept.
|
|
845
851
|
const solana = challenge.accepts.find((a) => isSolanaNetwork(a.network));
|
|
846
852
|
const evm = challenge.accepts.find(isEip3009Accept);
|
|
847
|
-
|
|
848
|
-
this.accept = (phantomDetected && solana) || evm || challenge.accepts[0];
|
|
853
|
+
this.accept = solana || evm || challenge.accepts[0];
|
|
849
854
|
this.setPrice(this.accept);
|
|
850
855
|
this.renderConnect();
|
|
851
856
|
} catch (err) {
|
package/types/index.d.ts
CHANGED
|
@@ -32,7 +32,10 @@ export interface SpendingCaps {
|
|
|
32
32
|
maxPerDay?: number | string;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* Global configuration. Defaults are vendor-neutral: `brand` and `builderCode`
|
|
37
|
+
* are `null` until a host opts in.
|
|
38
|
+
*/
|
|
36
39
|
export interface X402Config {
|
|
37
40
|
/**
|
|
38
41
|
* Origin serving the Solana `prepare`/`encode` checkout helpers
|
|
@@ -41,8 +44,9 @@ export interface X402Config {
|
|
|
41
44
|
* resolves from the script's own origin. `''` means same-origin.
|
|
42
45
|
*/
|
|
43
46
|
apiOrigin?: string | null;
|
|
44
|
-
|
|
45
|
-
|
|
47
|
+
/** `null` hides the footer attribution entirely (the default). */
|
|
48
|
+
brand?: Brand | null;
|
|
49
|
+
/** `null` disables the builder-code echo entirely (the default). */
|
|
46
50
|
builderCode?: BuilderCode | null;
|
|
47
51
|
/** CDN URL for `@solana/web3.js`, dynamic-imported on the Solana path. */
|
|
48
52
|
solanaWeb3Url?: string;
|