@zkp2p/sdk 0.15.0-rc.9 → 0.16.0-rc.0
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 +152 -1308
- package/dist/build-metadata.json +2 -2
- package/dist/{chunk-5XZVELCC.mjs → chunk-KOBIFF5A.mjs} +314 -191
- package/dist/{chunk-5XZVELCC.mjs.map → chunk-KOBIFF5A.mjs.map} +1 -1
- package/dist/{chunk-WDEEWFEU.mjs → chunk-PMFXZGDQ.mjs} +17 -7
- package/dist/chunk-PMFXZGDQ.mjs.map +1 -0
- package/dist/{chunk-ZGANVX76.mjs → chunk-RNISZEC5.mjs} +3 -3
- package/dist/{chunk-ZGANVX76.mjs.map → chunk-RNISZEC5.mjs.map} +1 -1
- package/dist/{chunk-YA67SM3A.mjs → chunk-RZFNRIED.mjs} +32 -12
- package/dist/chunk-RZFNRIED.mjs.map +1 -0
- package/dist/{currency-FI4VRX25.mjs → currency-BAZHTDT7.mjs} +4 -4
- package/dist/{currency-FI4VRX25.mjs.map → currency-BAZHTDT7.mjs.map} +1 -1
- package/dist/index.cjs +3922 -877
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +633 -16
- package/dist/index.d.ts +633 -16
- package/dist/index.mjs +3427 -579
- package/dist/index.mjs.map +1 -1
- package/dist/protocolViewerParsers-3P4EF54G.mjs +5 -0
- package/dist/{protocolViewerParsers-CX6TTLXB.mjs.map → protocolViewerParsers-3P4EF54G.mjs.map} +1 -1
- package/dist/react.cjs +87 -29
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.mts +2 -2
- package/dist/react.d.ts +2 -2
- package/dist/react.mjs +60 -22
- package/dist/react.mjs.map +1 -1
- package/dist/{vaultUtils-BDAD0pMx.d.mts → vaultUtils-DZMTnUHJ.d.mts} +122 -59
- package/dist/{vaultUtils-BDAD0pMx.d.ts → vaultUtils-DZMTnUHJ.d.ts} +122 -59
- package/package.json +7 -19
- package/dist/chunk-WDEEWFEU.mjs.map +0 -1
- package/dist/chunk-YA67SM3A.mjs.map +0 -1
- package/dist/protocolViewerParsers-CX6TTLXB.mjs +0 -5
package/README.md
CHANGED
|
@@ -4,1417 +4,261 @@
|
|
|
4
4
|
[](https://www.npmjs.com/package/@zkp2p/sdk)
|
|
5
5
|
[](https://opensource.org/licenses/MIT)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
TypeScript SDK for the Peer protocol on Base. `createPeer()` sells USDC for fiat with `peer.sell()` and buys USDC with `peer.buy()`. The lower-level `Zkp2pClient` creates and manages USDC deposits, quote liquidity, signal and fulfill intents, and run vault, staking, referral, and Seller Autopilot flows.
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
and chargeback-risk surface. The workspace version lives in `package.json`.
|
|
9
|
+
New intents use EscrowV2 and OrchestratorV4. The SDK retains reads for historical OrchestratorV3 intents. See the [client reference](https://docs.peer.xyz/developer/sdk/client-reference).
|
|
11
10
|
|
|
12
|
-
##
|
|
13
|
-
|
|
14
|
-
- Build maker, taker, vault, and embedded ramp flows from one client.
|
|
15
|
-
- Read live protocol state directly from ProtocolViewer instead of waiting on indexer sync.
|
|
16
|
-
- Signal new intents through EscrowV2/OrchestratorV3 and resolve existing intent owners across OrchestratorV2/V3 — legacy V1 resolution has been removed.
|
|
17
|
-
- Use prepareable write methods for smart accounts, relayers, gas estimation, and batching.
|
|
18
|
-
- Keep advanced analytics, fund activity history, and vault stats behind `client.indexer.*`.
|
|
19
|
-
|
|
20
|
-
## Who This Is For
|
|
21
|
-
|
|
22
|
-
- maker and liquidity-provider applications
|
|
23
|
-
- wallets and embedded onramp/offramp products
|
|
24
|
-
- backends that need contract-safe deposit and intent operations
|
|
25
|
-
- dashboards and analytics services that query `client.indexer.*`
|
|
26
|
-
- React apps that want first-party hooks instead of writing transaction glue
|
|
11
|
+
## Installation
|
|
27
12
|
|
|
28
|
-
|
|
13
|
+
```bash
|
|
14
|
+
npm install @zkp2p/sdk viem
|
|
15
|
+
```
|
|
29
16
|
|
|
30
|
-
|
|
31
|
-
- Indexer for history and filtering: use `client.indexer.*` for pagination, historical volumes, fund activities, daily snapshots, and vault analytics.
|
|
32
|
-
- Version-aware routing: new intents use EscrowV2 and OrchestratorV3; existing intent reads and lifecycle writes resolve their OrchestratorV2 or V3 owner. Legacy V1 fallbacks have been removed.
|
|
33
|
-
- Modular internals: intent, guardian, access-policy, staking, vault, and ProtocolViewer logic are extracted from `Zkp2pClient`, keeping the main client focused on orchestration.
|
|
34
|
-
- App-level rollout control: the SDK is capability-based. Product gating and phase flags belong in your app layer, not inside transaction helpers.
|
|
17
|
+
`viem` `^2.37.3` is a peer dependency. React (`>=16.8.0`) is optional and only needed for `@zkp2p/sdk/react`. Node.js runtimes need version 22 or later.
|
|
35
18
|
|
|
36
|
-
##
|
|
19
|
+
## Peer quickstart
|
|
37
20
|
|
|
38
|
-
|
|
39
|
-
[prepare/open/status flow](https://docs.peer.xyz/developer/peer-cash/guide#optional-venmo-receipt-linking).
|
|
40
|
-
It selects the matching environment and keeps linking separate from cash-out.
|
|
41
|
-
The direct SDK helpers below require `@zkp2p/sdk@0.14.2` or later.
|
|
21
|
+
Install the release candidate with `npm install @zkp2p/sdk@rc viem`.
|
|
42
22
|
|
|
43
|
-
|
|
44
|
-
The host passes the selected account hash; the user picks Gmail or Outlook,
|
|
45
|
-
which opens that provider's consent, or iCloud Mail, which takes an Apple
|
|
46
|
-
app-specific password on the Peer page.
|
|
23
|
+
### Sell Base USDC
|
|
47
24
|
|
|
48
25
|
```ts
|
|
49
|
-
import {
|
|
26
|
+
import { createPeer, isPeerError, usdc } from '@zkp2p/sdk';
|
|
27
|
+
import { createWalletClient, http } from 'viem';
|
|
28
|
+
import { privateKeyToAccount } from 'viem/accounts';
|
|
29
|
+
import { base } from 'viem/chains';
|
|
30
|
+
|
|
31
|
+
const signer = createWalletClient({
|
|
32
|
+
account: privateKeyToAccount('0x...'),
|
|
33
|
+
chain: base,
|
|
34
|
+
transport: http(),
|
|
35
|
+
});
|
|
36
|
+
const peer = createPeer({ environment: 'production' });
|
|
50
37
|
|
|
51
|
-
// Call directly from your button's click handler.
|
|
52
38
|
try {
|
|
53
|
-
await
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
39
|
+
const sale = await peer.sell(
|
|
40
|
+
{ amount: usdc('25'), receive: { platform: 'venmo', currency: 'USD', payee: '@alice' } },
|
|
41
|
+
{ signer },
|
|
42
|
+
);
|
|
43
|
+
// Persist sale.depositId: it resumes order(), watch() and withdraw() later.
|
|
44
|
+
for await (const order of peer.sell.watch(sale.depositId)) {
|
|
45
|
+
console.log(order.state, order.explain());
|
|
60
46
|
}
|
|
47
|
+
} catch (err) {
|
|
48
|
+
if (isPeerError(err)) console.error(err.code, err.remediation);
|
|
49
|
+
else throw err;
|
|
61
50
|
}
|
|
62
51
|
```
|
|
63
52
|
|
|
64
|
-
|
|
65
|
-
supports personal Microsoft accounts. No email suffix check runs. Missing
|
|
66
|
-
receipts produce a recoverable verification error.
|
|
67
|
-
Mobile widths request a normal browser tab; desktop requests a popup. The SDK
|
|
68
|
-
also reports blocked popups, closure, and a ten-minute timeout. Browser
|
|
69
|
-
opener isolation or a lost response can interrupt notification; reconcile with
|
|
70
|
-
`client.getSellerCredentialStatus()` or `apiGetSellerCredentialStatus()` before
|
|
71
|
-
retrying. Only `active` with a mailbox `credentialType`
|
|
72
|
-
(`isMailboxSellerCredentialType`, 0.14.7+: Gmail, Outlook or iCloud Mail) means
|
|
73
|
-
an inbox is linked. An already-linked inbox needs no reconnect. Linking is optional and never gates deposits.
|
|
74
|
-
|
|
75
|
-
Use matching Peer/Curator environments and configure Curator CORS for your host.
|
|
76
|
-
`peerOrigin` accepts HTTPS origins or HTTP localhost for development; Google must
|
|
77
|
-
have the exact callback origin registered. `getVenmoGmailConnectUrl` supports native
|
|
78
|
-
hosts and custom window handling with account-status polling at least ten seconds
|
|
79
|
-
apart. Deploy the hosted page before using the SDK helper. See the
|
|
80
|
-
[flow specification](https://github.com/zkp2p/zkp2p-clients/blob/main/docs/venmo-gmail-connect.md).
|
|
81
|
-
|
|
82
|
-
### X Money receipt linking
|
|
83
|
-
|
|
84
|
-
SDK `0.14.10` adds `getXMoneyConnectUrl` and `openXMoneyConnect`, using the same mailbox flow at
|
|
85
|
-
`/connect/xmoney`. Pass the registered `payeeDetails` hash and `payeeUsername`.
|
|
86
|
-
The normalized X username must hash to that identity. Both stay in the URL
|
|
87
|
-
fragment. X Money email notifications must be enabled and the inbox must contain
|
|
88
|
-
a signed received-payment receipt for that account. Gmail, personal Outlook and
|
|
89
|
-
iCloud Mail are supported. Deploy the hosted page before enabling this helper.
|
|
90
|
-
|
|
91
|
-
```ts
|
|
92
|
-
import { openXMoneyConnect } from '@zkp2p/sdk';
|
|
93
|
-
await openXMoneyConnect({ payeeDetails, payeeUsername: 'seller' });
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
The URL builder also accepts `returnUrl` for native hosts. Re-check the mailbox
|
|
97
|
-
credential status after return or dismissal, as with Venmo.
|
|
98
|
-
|
|
99
|
-
### Native app return
|
|
53
|
+
`peer.sell()` registers the payee, approves and deposits the USDC at the zero-spread oracle market rate, and returns once the deposit confirms. `watch()` yields `awaiting-buyer`, `matched` and `delivering` until the sale ends `delivered` or `returned`. `peer.sell.capabilities()` lists each platform's currencies and payee format. Curator checks that the handle exists on its platform, PayPal.Me usernames and Wisetags included (`PAYEE_NOT_FOUND` otherwise); a new Alipay payee needs a signed identity attestation (`PAYEE_VERIFICATION_REQUIRED`). Use `peer.sell.prepare()` for unsigned transactions, and `peer.sell.withdraw(depositId, { signer })` to take back unsold USDC.
|
|
100
54
|
|
|
101
|
-
|
|
102
|
-
supply their callback directly; no callback registration with Peer or deployment
|
|
103
|
-
setting is required. Deploy the hosted-page update before enabling this flow.
|
|
55
|
+
### Buy Base USDC
|
|
104
56
|
|
|
105
57
|
```ts
|
|
106
|
-
|
|
107
|
-
import * as WebBrowser from 'expo-web-browser';
|
|
108
|
-
|
|
109
|
-
// Use a callback scheme registered in your app binary.
|
|
110
|
-
const returnUrl = 'partner-app://venmo-linked';
|
|
111
|
-
const connectUrl = getVenmoGmailConnectUrl({ payeeDetails, returnUrl });
|
|
112
|
-
await WebBrowser.openAuthSessionAsync(connectUrl, returnUrl);
|
|
113
|
-
// Re-check your backend's seller-credential/status after return or dismissal.
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
Use a scheme registered in your Expo app binary; Expo Go is not a substitute
|
|
117
|
-
for testing your app's callback. See Expo's
|
|
118
|
-
[`openAuthSessionAsync` documentation](https://docs.expo.dev/versions/latest/sdk/webbrowser/#webbrowseropenauthsessionasyncurl-redirecturl-options).
|
|
119
|
-
The browser popup helper remains browser-only; native hosts use the URL builder.
|
|
120
|
-
|
|
121
|
-
Peer keeps the OAuth callback on Peer and verifies the selected account
|
|
122
|
-
before navigating to `returnUrl` unchanged. No OAuth codes, tokens, email,
|
|
123
|
-
account hash, or success flag are appended. If automatic navigation is blocked,
|
|
124
|
-
select **Return to your app**. Consent or verification errors stay visible and
|
|
125
|
-
also offer a manual return. A return, dismissal, or cancellation is not proof of
|
|
126
|
-
linking: only an active mailbox credential (`isMailboxSellerCredentialType`)
|
|
127
|
-
from the status API is linked.
|
|
128
|
-
|
|
129
|
-
Apps that need no SDK can build the same URL themselves:
|
|
130
|
-
`https://app.peer.xyz/connect/venmo?returnUrl=<URL-encoded-callback>#<payeeDetails>`.
|
|
131
|
-
The query parameter must precede the account hash fragment. Malformed URLs,
|
|
132
|
-
unsafe schemes, embedded credentials, and duplicate parameters are rejected
|
|
133
|
-
before consent or credential upload.
|
|
134
|
-
|
|
135
|
-
Omit `returnUrl` or leave it empty to keep the existing behavior: Peer attempts
|
|
136
|
-
`window.close()` after verification. Script-opened desktop popups can close;
|
|
137
|
-
mobile browser tabs that disallow closure keep the success message visible.
|
|
138
|
-
|
|
139
|
-
### Popup customization
|
|
58
|
+
const peer = createPeer({ environment: 'production', getAuthorizationToken: getAccessToken });
|
|
140
59
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
popup: { width: 500, height: 620 },
|
|
147
|
-
appearance: {
|
|
148
|
-
logoUrl: 'https://your-app.example/logo.png',
|
|
149
|
-
logoAlt: 'Your app',
|
|
150
|
-
backgroundColor: '#FFFFFF',
|
|
151
|
-
textColor: '#172033',
|
|
152
|
-
secondaryTextColor: '#636B7A',
|
|
153
|
-
buttonColor: '#6246EA',
|
|
154
|
-
buttonTextColor: '#FFFFFF',
|
|
155
|
-
buttonHoverColor: '#5035CC',
|
|
156
|
-
focusColor: '#6246EA',
|
|
157
|
-
fontFamily: 'Arial, sans-serif',
|
|
158
|
-
headingFontFamily: 'Arial, sans-serif',
|
|
159
|
-
headingTextTransform: 'none',
|
|
160
|
-
buttonTextTransform: 'none',
|
|
161
|
-
headingFontSize: 30,
|
|
162
|
-
buttonBorderRadius: 24,
|
|
163
|
-
buttonHeight: 52,
|
|
164
|
-
logoHeight: 44,
|
|
165
|
-
},
|
|
60
|
+
const [offer] = await peer.buy.quote({
|
|
61
|
+
platforms: ['venmo'],
|
|
62
|
+
currency: 'USD',
|
|
63
|
+
amount: { fiat: usdc('50') }, // or { usdc: usdc('50') } for an exact USDC amount
|
|
64
|
+
recipient: signer.account.address,
|
|
166
65
|
});
|
|
66
|
+
const { intentHash } = await peer.buy(offer, { signer }); // locks the seller's USDC
|
|
67
|
+
const { payee } = await peer.buy.payment(intentHash); // pay this Venmo user off-platform
|
|
68
|
+
await peer.buy.complete({ intentHash, proof }, { signer }); // proof from the PeerAuth extension
|
|
167
69
|
```
|
|
168
70
|
|
|
169
|
-
|
|
170
|
-
allow CORS); a failed font uses the fallback stack. Failed partner images show Peer. Asset URLs require HTTPS, with HTTP localhost allowed for development.
|
|
171
|
-
|
|
172
|
-
`VenmoGmailAppearance` also exposes `cardBackgroundColor`, `cardBorderRadius`,
|
|
173
|
-
`borderColor`, `contentWidth`, `padding`, `gap`, `fontSize`, `successColor` and
|
|
174
|
-
`errorColor`. Colors use `#RGB` or `#RRGGBB`; sizes are pixels. Invalid options
|
|
175
|
-
throw `ValidationError` before the popup opens. Arbitrary CSS/HTML is not accepted.
|
|
176
|
-
Choose contrasting text, button and focus colors.
|
|
71
|
+
`getAuthorizationToken` returns the buyer's Privy access token (for example Privy's `getAccessToken`) for an account linked to `signer`; Curator's intent signing and payee reveal use it, and the buyer's payment identity must be enrolled for the rail when Curator requires it. A failure before broadcast rejects with `TRANSACTION_PREPARATION_FAILED` and is safe to retry. After `TRANSACTION_SUBMISSION_UNKNOWN` or `TRANSACTION_STATUS_UNKNOWN`, the intent may already exist: check the buyer's open intents before calling `peer.buy()` again. Each offer carries its fiat and USDC amounts, `expiresAt`, and whether Curator requires dispute-protection stake.
|
|
177
72
|
|
|
178
|
-
|
|
179
|
-
regular tab, whose size and presentation are controlled by the browser. Branding
|
|
180
|
-
and styles survive the OAuth callback; account binding, consent copy,
|
|
181
|
-
receipt verification and error codes remain unchanged. Google and Microsoft
|
|
182
|
-
control their own consent pages' appearance.
|
|
183
|
-
|
|
184
|
-
## Installation
|
|
185
|
-
|
|
186
|
-
```bash
|
|
187
|
-
npm install @zkp2p/sdk viem
|
|
188
|
-
# or
|
|
189
|
-
pnpm add @zkp2p/sdk viem
|
|
190
|
-
# or
|
|
191
|
-
bun add @zkp2p/sdk viem
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
If you use React hooks, add React as well:
|
|
195
|
-
|
|
196
|
-
```bash
|
|
197
|
-
pnpm add react
|
|
198
|
-
```
|
|
199
|
-
|
|
200
|
-
## Quick Start
|
|
73
|
+
## Quick start
|
|
201
74
|
|
|
202
75
|
```ts
|
|
203
76
|
import { Zkp2pClient } from '@zkp2p/sdk';
|
|
204
|
-
import { createWalletClient,
|
|
77
|
+
import { createWalletClient, http } from 'viem';
|
|
78
|
+
import { privateKeyToAccount } from 'viem/accounts';
|
|
205
79
|
import { base } from 'viem/chains';
|
|
206
80
|
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
transport: custom(window.ethereum),
|
|
210
|
-
});
|
|
81
|
+
const account = privateKeyToAccount('0x...');
|
|
82
|
+
const walletClient = createWalletClient({ account, chain: base, transport: http() });
|
|
211
83
|
|
|
212
84
|
const client = new Zkp2pClient({
|
|
213
85
|
walletClient,
|
|
214
86
|
chainId: base.id,
|
|
87
|
+
baseApiUrl: 'https://api.zkp2p.xyz',
|
|
215
88
|
});
|
|
216
89
|
```
|
|
217
90
|
|
|
218
|
-
`
|
|
219
|
-
|
|
220
|
-
## Environment and Authentication
|
|
221
|
-
|
|
222
|
-
- Supported runtime environments: `'production'`, `'preproduction'`, `'staging'`
|
|
223
|
-
- `runtimeEnv` default: `'production'`
|
|
224
|
-
- `rpcUrl`: optional RPC URL override (defaults to wallet's chain RPC)
|
|
225
|
-
- `rpcTransport`: optional viem transport override for contract reads
|
|
226
|
-
- `apiKey`: optional curator API key sent as `x-api-key`. Maker identities in quotes and maker reads require an approved key with maker-read permission; seller verification requires its own scope
|
|
227
|
-
- `authorizationToken` / `getAuthorizationToken`: optional bearer auth for indexer flows and authenticated curator account APIs, including Venmo iCloud Mail onboarding
|
|
228
|
-
- `indexerApiKey`: optional `x-api-key` for indexer proxy auth
|
|
229
|
-
- `indexerUrl` and `baseApiUrl`: override defaults when you are targeting custom deployments
|
|
230
|
-
- `timeouts`: `{ api?: number }` — API timeout in milliseconds (default 15000)
|
|
231
|
-
|
|
232
|
-
**No external API key is required.** `createDeposit`, `registerPayeeDetails`, `getQuote`, `signalIntent`, and the rest of the public SDK flows work without `apiKey` or `authorizationToken`. When `baseApiUrl` is configured, `signalIntent()` uses curator `/v3/sign` without auth. Curator's 409 "enforced on-chain" reply (a deposit with no intent gating service) becomes a direct, signature-free signal on OrchestratorV3. On OrchestratorV4, whose `IntentSignalPolicy` checks a gating signature on every intent, that reply throws `ValidationError` before anything is signed. Any other 409 throws with curator's message. Public quotes omit payout handles, Telegram contacts, and maker metadata. SDK, CLI, and agent integrations must request an approved API key with maker-read permission from Peer to fetch those details. Configure `apiKey` on `Zkp2pClient` to receive optional `maker.offchainId` and `payeeData.offchainId` in quotes. For the full maker record, use `apiGetPayeeDetails({ processorName, hashedOnchainId }, baseApiUrl, timeoutMs, apiKey)`; without an approved key Curator answers HTTP 401, or 403 for an internal key that lacks the grant. Web and mobile reveal payment details only after signaling an intent, using the owning Privy account at `GET /v2/makers/intent/:intentHash`.
|
|
233
|
-
|
|
234
|
-
Indexer defaults by environment:
|
|
235
|
-
|
|
236
|
-
- `production`: `https://indexer.zkp2p.xyz/v1/graphql`
|
|
237
|
-
- `preproduction`: `https://indexer-preprod.zkp2p.xyz/v1/graphql`
|
|
238
|
-
- `staging`: `https://indexer-staging.zkp2p.xyz/v1/graphql`
|
|
239
|
-
|
|
240
|
-
## Core Capabilities
|
|
241
|
-
|
|
242
|
-
| Area | Stable surface |
|
|
243
|
-
| ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
244
|
-
| Deposits | `createDeposit`, `addFunds`, `removeFunds`, `withdrawDeposit`, `ensureAllowance`, `setAcceptingIntents`, `setIntentRange`, `setCurrencyMinRate`, `setRetainOnEmpty` |
|
|
245
|
-
| Payment methods and currencies | `addPaymentMethods`, `removePaymentMethod`, `setPaymentMethodActive`, `addCurrencies`, `removeCurrency`, `deactivateCurrency`, `pruneExpiredIntents` |
|
|
246
|
-
| Intents | `signalIntent`, `fulfillIntent`, `cancelIntent`, `releaseFundsToPayer`, `extendIntent`, `getFulfillIntentInputs`, `getIntentGuardianPolicy`, `quoteIntentExtension`, `getIntentGuardianPayerFunding`, `extendIntentLifetime` |
|
|
247
|
-
| Deposit access policy | `client.accessPolicy.*` reads and historical-policy unwind operations |
|
|
248
|
-
| Prepared transactions | `client.prepareCreateDeposit(...)`, `client.signalIntent.prepare(...)`, `client.fulfillIntent.prepare(...)`, `client.setVaultFee.prepare(...)`, and equivalent prepare flows across the rest of the prepareable write surface |
|
|
249
|
-
| Payee and quote APIs | `registerPayeeDetails`, `resolvePayeeHash`, `getQuote`, `getQuotesBestByPlatform` |
|
|
250
|
-
| Seller automated release | `uploadSellerCredential`, `getSellerCredentialStatus`, `verifySellerPayment` |
|
|
251
|
-
| Delegation and hooks | `setDelegate`, `removeDelegate`, `setRateManager`, `clearRateManager`, `setDepositRateManager`, `clearDepositRateManager`, `setDepositPreIntentHook`; whitelist-hook helpers remain for V2 integrations |
|
|
252
|
-
| Vault / DRM | `createRateManager`, `setVaultMinRate`, `setVaultMinRatesBatch`, `setVaultFee`, `setVaultConfig`, `getDepositRateManager`, `getManagerFee`, `getEffectiveRate` |
|
|
253
|
-
| Oracle config | `setOracleRateConfig`, `setOracleRateConfigBatch`, `removeOracleRateConfig`, `updateCurrencyConfigBatch`, `deactivateCurrenciesBatch`, `supportsInlineOracleRateConfig`, `validateOracleFeedsOnChain` |
|
|
254
|
-
| RPC reads | `getDeposits`, `getDeposit`, `getDepositsById`, `getIntents`, `getIntent`, `getPvDepositById`, `getPvDepositsFromIds`, `getPvAccountDeposits`, `getPvAccountIntents`, `getPvIntent` |
|
|
255
|
-
| Indexer | `client.indexer.getDeposits`, `getDepositsWithRelations`, `getDepositById`, `getDepositsByIds`, `getDepositsByIdsWithRelations`, `getDepositsByPayeeHash`, `getIntentsForDeposits`, `getOwnerIntents`, `getIntentsByRateManager`, `getIntentByHash`, `getExpiredIntents`, `getFulfilledIntentEvents`, `getIntentFulfillmentAmounts`, `getFulfillmentAndPayment`, `getDepositFundActivities`, `getMakerFundActivities`, `getDepositDailySnapshots`, `getProfitSnapshotsByDeposits`, `getRateManagers`, `getRateManagerDetail`, `getRateManagerDelegations`, `getDelegationForDeposit`, `getManagerDailySnapshots`, `getManualRateUpdates`, `getOracleConfigUpdates`, `query` |
|
|
256
|
-
| React hooks | `@zkp2p/sdk/react` exports hooks for deposits, intents, delegation, vaults, and payment methods |
|
|
257
|
-
| Attribution | ERC-8021 helpers like `sendTransactionWithAttribution`, `encodeWithAttribution`, and `txOverrides.referrer` support |
|
|
258
|
-
| Taker staking | `ensureStakeAllowance`, `depositStake`, `withdrawStake`, `claim`, `setTakerAuthorization`, `selectStakeOwner`, `clearStakeOwner`, direct StakeVault reads, and `client.indexer.getStakingState()` |
|
|
259
|
-
| Chargeback keepers | `releaseMaturedDisputeProtectionIntent`, `releaseMaturedDisputeProtectionIntents`, with caller-pinned `disputeProtectionPolicyAddress` support |
|
|
260
|
-
|
|
261
|
-
Payment attestation requests require a checksummed `intent.owner` for O2, O3 and O4.
|
|
262
|
-
`getFulfillIntentInputs`, `fulfillIntent` and `verifySellerPayment` resolve the
|
|
263
|
-
signaler from the intent's own on-chain orchestrator and fail if it cannot be
|
|
264
|
-
resolved. They never substitute the connected wallet, recipient or indexer owner.
|
|
265
|
-
Low-level payment adapters require callers to supply that on-chain owner.
|
|
266
|
-
|
|
267
|
-
## Extension Metadata Bridge
|
|
268
|
-
|
|
269
|
-
Use `createPeerExtensionSdk()` when a page needs the Peer extension to open a
|
|
270
|
-
provider auth tab and interact with the Peer TEE protocol. The extension owns
|
|
271
|
-
provider-tab capture and Buyer TEE session encryption. For seller automated
|
|
272
|
-
release, the extension captures seller session material, creates the encrypted
|
|
273
|
-
attestation-service bundle, and returns only that bundle plus the maker
|
|
274
|
-
`offchainId`. The page owns maker payee registration and curator credential
|
|
275
|
-
storage.
|
|
276
|
-
|
|
277
|
-
```ts
|
|
278
|
-
import { createPeerExtensionSdk } from '@zkp2p/sdk';
|
|
91
|
+
Set `baseApiUrl` so `signalIntent()` can fetch gating signatures from Peer's API. For browser signing, pass Privy's `getAccessToken` as `getAuthorizationToken` and use a wallet linked to that user. Servers can [sign each API request with the customer's wallet](https://docs.peer.xyz/developer/server-side-integration) and pass the returned gating signature to the SDK.
|
|
279
92
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
if ((await peer.getState()) === 'needs_connection') {
|
|
283
|
-
await peer.requestConnection();
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
const unsubscribe = peer.onMetadataMessage((message) => {
|
|
287
|
-
if (message.sarCredentialCapture) {
|
|
288
|
-
console.log('SAR credential bundle captured', message.sarCredentialCapture.credentialBundle);
|
|
289
|
-
return;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
console.log('captured payment metadata', message.metadata);
|
|
293
|
-
});
|
|
93
|
+
Maker registration through `registerPayeeDetails()` and deposit preparation also sends the current token, or `authorizationToken` when no getter is configured, along with `apiHeaders`. New makers can still register anonymously; updating an existing maker requires its owner's Privy token. An `x-pp-key` header skips automatic bearer lookup. Standalone `apiPostDepositDetails(request, baseApiUrl, timeoutMs?, authorizationToken?, headers?)` accepts the same optional auth and headers.
|
|
294
94
|
|
|
295
|
-
|
|
296
|
-
actionType: 'transfer_venmo',
|
|
297
|
-
captureMode: 'buyerTee',
|
|
298
|
-
platform: 'venmo',
|
|
299
|
-
attestationServiceUrl: 'https://attestation.zkp2p.xyz',
|
|
300
|
-
});
|
|
301
|
-
```
|
|
95
|
+
When payment-account verification is required, first check authenticated `GET /v3/identity?platform=<rail>&callerAddress=<wallet>`. If unverified, obtain the attestation service's canonical signed `/identity` output and submit it unchanged as `{ identityAttestation }` to authenticated `POST /v3/identity`. Curator checks persisted verification on every public signing request; an expired, revoked, or unavailable identity must stop the purchase. Browser clients use their Privy access token on both identity endpoints. Servers use the wallet-signature headers described in the server-side guide. Trusted Peer Pay integrations retain their existing `x-pp-key` signing path without requesting a Privy token.
|
|
302
96
|
|
|
303
|
-
|
|
304
|
-
origins. Trusted Peer hosts and `localhost` are already connected.
|
|
305
|
-
`authenticate()` identifies the provider with `platform` and
|
|
306
|
-
`actionType`; the extension fetches the matching extension-managed template
|
|
307
|
-
from `https://api.zkp2p.xyz/providers/`. Buyer TEE is API/template driven: pass `captureMode: "buyerTee"` plus
|
|
308
|
-
`attestationServiceUrl`, and the extension returns encrypted session material.
|
|
309
|
-
For Cash App and Amazon Pay UPI SAR, pass `captureMode: "sellerCredential"` and optionally pass
|
|
310
|
-
`attestationServiceUrl` only when overriding the extension's production
|
|
311
|
-
attestation default. The extension returns `sarCredentialCapture.credentialBundle`
|
|
312
|
-
plus `offchainId`. The page should call `apiUploadSellerCredentialBundle()` to
|
|
313
|
-
register maker payee details with curator, compare the registered hash to the
|
|
314
|
-
bundle `payeeIdHash`, and store the encrypted bundle with curator. Plaintext
|
|
315
|
-
seller session material is never returned to the page.
|
|
316
|
-
|
|
317
|
-
`Zkp2pClient.uploadSellerCredential()` supports Cash App, Wise, and Amazon Pay UPI
|
|
318
|
-
plaintext input from trusted runtimes. It creates the encrypted bundle, then uses
|
|
319
|
-
`apiUploadSellerCredentialBundle()` for storage. Venmo, PayPal, and X Money use
|
|
320
|
-
the [mailbox upload helpers](#seller-credential-status) for Gmail, personal
|
|
321
|
-
Outlook, or iCloud Mail.
|
|
322
|
-
|
|
323
|
-
## Create a Deposit
|
|
97
|
+
## Create a deposit
|
|
324
98
|
|
|
325
99
|
```ts
|
|
326
|
-
|
|
100
|
+
const usdc = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913';
|
|
101
|
+
const amount = 1_000_000000n; // 1,000 USDC
|
|
102
|
+
|
|
103
|
+
const approval = await client.ensureAllowance({ token: usdc, amount });
|
|
104
|
+
// When approval.hadAllowance is false, wait for approval.hash to confirm.
|
|
327
105
|
|
|
328
|
-
const
|
|
329
|
-
token:
|
|
330
|
-
amount
|
|
331
|
-
intentAmountRange: { min:
|
|
106
|
+
const { hash } = await client.createDeposit({
|
|
107
|
+
token: usdc,
|
|
108
|
+
amount,
|
|
109
|
+
intentAmountRange: { min: 10_000000n, max: 500_000000n },
|
|
332
110
|
processorNames: ['revolut'],
|
|
333
|
-
payeeData: [{ offchainId: '
|
|
334
|
-
conversionRates: [[{ currency:
|
|
111
|
+
payeeData: [{ offchainId: 'your-revtag' }],
|
|
112
|
+
conversionRates: [[{ currency: 'USD', conversionRate: '1020000000000000000' }]], // 1.02
|
|
335
113
|
});
|
|
336
|
-
|
|
337
|
-
console.log(result.hash);
|
|
338
|
-
console.log(result.depositDetails);
|
|
339
114
|
```
|
|
340
115
|
|
|
341
|
-
`
|
|
342
|
-
`{ depositDetails, hash }`. It never configures a deposit whitelist or sends
|
|
343
|
-
follow-up access-policy transactions. `prepareCreateDeposit()` likewise prepares
|
|
344
|
-
only the deposit transaction.
|
|
345
|
-
|
|
346
|
-
If you do not pass `payeeDetailsHashes`, `createDeposit()` can register the payee details for you. If you want to pre-register or reuse hashes across deposits, use `registerPayeeDetails()` first.
|
|
116
|
+
Manage the deposit with `addFunds`, `removeFunds`, `setAcceptingIntents`, `setIntentRange`, `setCurrencyMinRate`, and `withdrawDeposit`.
|
|
347
117
|
|
|
348
|
-
|
|
349
|
-
environment. Production and preproduction use
|
|
350
|
-
`0x83671606454fA72ba1e2831E18C5090D25629414`, enabling prepaid intent-lifetime
|
|
351
|
-
extensions. Pass `intentGuardian` explicitly only when integrating a custom
|
|
352
|
-
guardian.
|
|
353
|
-
|
|
354
|
-
## Payee Registration and Quotes
|
|
118
|
+
## Quote, signal, and fulfill
|
|
355
119
|
|
|
356
120
|
```ts
|
|
357
|
-
import { resolvePaymentMethodHash } from '@zkp2p/sdk';
|
|
358
|
-
|
|
359
|
-
// App-specific: request this from the ZKP2P attestation service after capturing
|
|
360
|
-
// Wise registration material through PeerAuth / Buyer TEE.
|
|
361
|
-
const identityAttestation = await getWiseIdentityAttestation();
|
|
362
|
-
|
|
363
|
-
const { hashedOnchainIds } = await client.registerPayeeDetails({
|
|
364
|
-
processorNames: ['wise'],
|
|
365
|
-
payeeData: [
|
|
366
|
-
{
|
|
367
|
-
offchainId: 'maker-wisetag',
|
|
368
|
-
// Wise maker registration requires an identity attestation from the
|
|
369
|
-
// attestation service. Pass it directly or inside metadata.identityAttestation.
|
|
370
|
-
identityAttestation,
|
|
371
|
-
},
|
|
372
|
-
],
|
|
373
|
-
});
|
|
374
|
-
|
|
375
121
|
const quote = await client.getQuote({
|
|
376
122
|
paymentPlatforms: ['wise'],
|
|
377
123
|
fiatCurrency: 'USD',
|
|
378
|
-
user:
|
|
379
|
-
recipient:
|
|
124
|
+
user: account.address,
|
|
125
|
+
recipient: account.address,
|
|
380
126
|
destinationChainId: 8453,
|
|
381
|
-
destinationToken:
|
|
382
|
-
amount: '
|
|
383
|
-
isExactFiat: true,
|
|
384
|
-
});
|
|
385
|
-
|
|
386
|
-
const payeeHash = await client.resolvePayeeHash(
|
|
387
|
-
42n,
|
|
388
|
-
resolvePaymentMethodHash('wise', { env: 'production' }),
|
|
389
|
-
);
|
|
390
|
-
```
|
|
391
|
-
|
|
392
|
-
`getQuote()` returns available liquidity plus payee details when authenticated. Use `getQuotesBestByPlatform()` to fetch the best quote per supported payment platform in a single call (handy for cross-platform comparison UIs).
|
|
393
|
-
|
|
394
|
-
## Taker Staking
|
|
395
|
-
|
|
396
|
-
```ts
|
|
397
|
-
const amount = 250_000000n;
|
|
398
|
-
const approval = await client.ensureStakeAllowance({ amount });
|
|
399
|
-
// Wait for approval.hash to confirm when hadAllowance is false.
|
|
400
|
-
|
|
401
|
-
await client.depositStake({ amount }); // sender becomes the stake owner
|
|
402
|
-
await client.withdrawStake({ amount: 50_000000n }); // immediate, free stake only
|
|
403
|
-
await client.claim(); // withdraws the caller's full claimable balance
|
|
404
|
-
|
|
405
|
-
// Safe sponsorship is a two-actor flow:
|
|
406
|
-
await client.setTakerAuthorization({ taker, authorized: true }); // signed by the Safe
|
|
407
|
-
await client.selectStakeOwner({ stakeOwner: safeAddress }); // signed by the taker
|
|
408
|
-
await client.clearStakeOwner(); // taker returns to self-stake
|
|
409
|
-
|
|
410
|
-
// Explicit vaults are verified through the live stack independently by each client.
|
|
411
|
-
const onchain = await client.getStakeVaultState({
|
|
412
|
-
staker: takerAddress,
|
|
413
|
-
taker: takerAddress,
|
|
414
|
-
});
|
|
415
|
-
|
|
416
|
-
const indexed = await client.indexer.getStakingState({
|
|
417
|
-
chainId: 8453,
|
|
418
|
-
environment: 'base',
|
|
419
|
-
vaultAddress: (await client.getActiveStakeVaultContract()).address,
|
|
420
|
-
disputeProtectionPolicyAddress: client.getDisputeProtectionPolicyContract().address,
|
|
421
|
-
taker: takerAddress,
|
|
422
|
-
// Always supply the effective owner from the fresh on-chain read.
|
|
423
|
-
stakeOwner: onchain.stakeOwner,
|
|
424
|
-
});
|
|
425
|
-
// indexed: effective/raw ownership, total/locked/free stake, claimable,
|
|
426
|
-
// authorizations, Vault controller, per-row provenance, and the indexer head.
|
|
427
|
-
|
|
428
|
-
const locks = await client.indexer.getStakeLocks({
|
|
429
|
-
chainId: 8453,
|
|
430
|
-
vaultAddress: (await client.getActiveStakeVaultContract()).address,
|
|
431
|
-
stakeOwner: onchain.stakeOwner,
|
|
432
|
-
status: 'ACTIVE',
|
|
433
|
-
limit: 50,
|
|
434
|
-
});
|
|
435
|
-
|
|
436
|
-
const activity = await client.indexer.getStakeActivity({
|
|
437
|
-
chainId: 8453,
|
|
438
|
-
vaultAddress: (await client.getActiveStakeVaultContract()).address,
|
|
439
|
-
merchant: takerAddress,
|
|
440
|
-
orderDirection: 'desc', // Newest first; defaults to asc for chronological ingestion.
|
|
441
|
-
limit: 50,
|
|
442
|
-
});
|
|
443
|
-
|
|
444
|
-
// merchant is optional: omit it for the vault-wide activity feed.
|
|
445
|
-
// When supplied, it matches the event stake owner or taker.
|
|
446
|
-
// Keep orderDirection unchanged when passing activity.nextCursor for older pages.
|
|
447
|
-
|
|
448
|
-
const totals = await client.indexer.getStakeTotals({
|
|
449
|
-
chainId: 8453,
|
|
450
|
-
vaultAddress: (await client.getActiveStakeVaultContract()).address,
|
|
451
|
-
});
|
|
452
|
-
// totals.totalStaked and totals.totalLocked are decimal strings in token base units.
|
|
453
|
-
// totals.stakerCount counts owners whose stake balance is greater than zero.
|
|
454
|
-
|
|
455
|
-
// Includes RELEASED and DISPUTED records after the V2 policy deletes its on-chain protection.
|
|
456
|
-
const protection = await client.indexer.getDisputeProtectionIntentByHash({
|
|
457
|
-
chainId: 8453,
|
|
458
|
-
intentHash,
|
|
459
|
-
}); // null when no indexed record exists; indexer errors propagate.
|
|
460
|
-
|
|
461
|
-
const finalizedDisputes = await client.indexer.getDisputeProtectionIntents({
|
|
462
|
-
chainId: 8453,
|
|
463
|
-
policyAddress: client.getDisputeProtectionPolicyContract().address,
|
|
464
|
-
throughBlockNumber: finalizedBlockNumber.toString(),
|
|
465
|
-
limit: 50,
|
|
466
|
-
});
|
|
467
|
-
```
|
|
468
|
-
|
|
469
|
-
Stake and deposit-protection writes expose direct and `.prepare()` variants:
|
|
470
|
-
`depositStake`, `withdrawStake`, `claim`, `setTakerAuthorization`,
|
|
471
|
-
`selectStakeOwner`, `clearStakeOwner`, and `setDisputeProtectionEnabled`.
|
|
472
|
-
There is no withdrawal request, cooldown, or exit
|
|
473
|
-
lifecycle — `withdrawStake` is immediate up to `freeStake`, and `claim`
|
|
474
|
-
withdraws the complete claimable balance. Chargebackable capacity is exactly
|
|
475
|
-
the effective owner's free stake (1:1); never sum a taker's self-stake with a
|
|
476
|
-
sponsor's stake.
|
|
477
|
-
|
|
478
|
-
`getDisputeProtectionStacks()` discovers `{ current, draining }` from
|
|
479
|
-
OrchestratorV4 and OrchestratorV3 respectively, following O4 settlementPolicy to its vault, and the August/O3 hook to its policy and
|
|
480
|
-
vault. Discovery is cached for 30 seconds; failures are retried. The active vault
|
|
481
|
-
is the V4 vault when V4 is deployed, otherwise the V3 vault. Known previous vaults
|
|
482
|
-
remain selectable with `stakeVaultAddress` for reads and withdrawals; on staging these
|
|
483
|
-
are the August and Bypass vaults. The Bypass policy also stays known, so O3 intents
|
|
484
|
-
holding records there still resolve. O4 discovery verifies
|
|
485
|
-
that O4 is registered in the policy's `orchestratorRegistry()` and `vault.isController(policy)`. V2 uses
|
|
486
|
-
the StakeVaultV2 ABI; August vaults retain StakeVault and its single controller. A missing
|
|
487
|
-
current stack fails closed. `@zkp2p/contracts-v2@0.4.4-rc.13` bundles the unchanged
|
|
488
|
-
Base staging V4 stack and the Base production V4 suite. Production and
|
|
489
|
-
preproduction (which uses production contracts) resolve new signals to
|
|
490
|
-
OrchestratorV4 `0x74c55679268FAfB493864915aD16A320AB8c40Ba` and read O4 intents
|
|
491
|
-
through ProtocolViewerV4 `0x685123dB5fE2b88D00ED3764c088d600D9B2b6Fc`.
|
|
492
|
-
Existing O3/O2 intents keep their paths. Base `INTENT_EXPIRATION_PERIOD` stays
|
|
493
|
-
21600 seconds. The Base OrchestratorRegistry registers both O4 and O3
|
|
494
|
-
(`isOrchestrator` read on-chain, 2026-10-30). See [vendor provenance](../../vendor/README.md).
|
|
495
|
-
|
|
496
|
-
Explicit vault addresses passed to stake reads, writes and allowance setup are verified
|
|
497
|
-
against bundled deployments or the trusted V4 live stack, cached per client for 30 seconds.
|
|
498
|
-
Use `await client.resolveStakeVaultContract({ stakeVaultAddress })` when contract
|
|
499
|
-
coordinates are needed before a direct read. `getStakeVaultContract` remains a
|
|
500
|
-
synchronous lookup of already-known vaults.
|
|
501
|
-
|
|
502
|
-
`getAdmissionsPaused`, `getRiskWindow`, `isDisputeProtectionEnabled` and
|
|
503
|
-
`setDisputeProtectionEnabled` target only the August V1 policy behind
|
|
504
|
-
OrchestratorV3. An explicit V2 address or a missing V3 stack fails closed.
|
|
505
|
-
V2 has no on-chain risk-window or pause getter; `StakeVaultState.admissionsPaused`
|
|
506
|
-
is omitted for V2 vaults. Use the attestor rail policy for quote-time defaults.
|
|
507
|
-
Releases look up each intent's original policy;
|
|
508
|
-
a batch spanning policies throws `ValidationError`.
|
|
509
|
-
|
|
510
|
-
The August vault's controller is the `DisputeProtectionPolicy` contract. It owns
|
|
511
|
-
per-payment-method risk windows (`getRiskWindow(paymentMethodHash)`),
|
|
512
|
-
and the global `admissionsPaused()` switch. The selected `@zkp2p/contracts-v2`
|
|
513
|
-
bundle resolves the StakeVault, DisputeProtectionPolicy, and OrchestratorV3 for
|
|
514
|
-
both the production and staging bundles; a bundle without them fails closed
|
|
515
|
-
(`VITE_BASE_STAGING_STAKE_VAULT_ADDRESS` /
|
|
516
|
-
`VITE_BASE_STAGING_DISPUTE_PROTECTION_POLICY_ADDRESS` overrides support local
|
|
517
|
-
deployments).
|
|
518
|
-
|
|
519
|
-
Keeper writes are direct and prepareable:
|
|
520
|
-
|
|
521
|
-
```ts
|
|
522
|
-
// August V1 policy behind OrchestratorV3 only.
|
|
523
|
-
const enableProtection = await client.setDisputeProtectionEnabled.prepare({
|
|
524
|
-
escrow: depositEscrow,
|
|
525
|
-
depositId: 42n,
|
|
526
|
-
paymentMethod: paymentMethodHash,
|
|
527
|
-
enabled: true,
|
|
528
|
-
});
|
|
529
|
-
|
|
530
|
-
const release = await client.releaseMaturedDisputeProtectionIntents.prepare({
|
|
531
|
-
intentHashes: [intentHash],
|
|
532
|
-
disputeProtectionPolicyAddress: snapshottedPolicyAddress,
|
|
127
|
+
destinationToken: usdc,
|
|
128
|
+
amount: '250000000', // 250 USD, in 6-decimal units
|
|
533
129
|
});
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
An explicit `disputeProtectionPolicyAddress` is caller-pinned and may be outside the
|
|
537
|
-
client's configured deployment context, allowing sweepers to group intents by
|
|
538
|
-
their snapshotted policy deployment without a later SDK configuration change
|
|
539
|
-
rerouting them.
|
|
540
|
-
|
|
541
|
-
`client.indexer.getStakingState()` composes the `@zkp2p/indexer-schema`
|
|
542
|
-
account rows, preserves their individual update blocks, and reports the
|
|
543
|
-
chain's actual indexer head as `freshness.indexerHeadBlockNumber`. Its
|
|
544
|
-
caller-supplied `stakeOwner` must come from a fresh on-chain
|
|
545
|
-
`stakeOwnerOf(taker)` read; stale indexed ownership is reported without
|
|
546
|
-
attributing another owner's balance. Refetch immediately before signaling; the
|
|
547
|
-
contract stays authoritative.
|
|
548
|
-
|
|
549
|
-
The three history methods return `{ items, nextCursor, asOf }`; finalized
|
|
550
|
-
disputes also return `endCursor`. Cursors are
|
|
551
|
-
opaque keysets, limits are integers from 1 through 100, and all numeric values
|
|
552
|
-
are unsigned decimal strings. `asOf` identifies the latest row observed in the
|
|
553
|
-
returned page; it is not an indexer-head or strong-consistency guarantee.
|
|
554
|
-
The finalized-dispute page requires a code-owned `throughBlockNumber`; use the
|
|
555
|
-
same finalized cutoff for every cursor in one ingestion pass. Follow
|
|
556
|
-
`nextCursor` while it is non-null, then atomically persist the terminal page's
|
|
557
|
-
`endCursor` with its final block/log position; `endCursor` is null only for an
|
|
558
|
-
empty page.
|
|
559
|
-
|
|
560
|
-
The existing readiness API verifies the V3 manifest only. V4 readiness is pending
|
|
561
|
-
the new deployment manifest.
|
|
562
|
-
|
|
563
|
-
The manifest reader pins every code and state read to one `asOfBlock`, including exact
|
|
564
|
-
governance owners, authorization sets, attestation witnesses, and signature
|
|
565
|
-
thresholds. It distinguishes
|
|
566
|
-
`recognized_predecessor`, `passive_successor`, `active_successor_verified`,
|
|
567
|
-
`verified_no_hook`, and `mismatch`. A dormant successor is checked only when
|
|
568
|
-
`{ verifyPassiveSuccessor: true }` is supplied. An exact active successor stays
|
|
569
|
-
verified while `orchestratorPaused`, `allowMultipleIntents`, and
|
|
570
|
-
`policyAdmissionsPaused` report operational traffic gates;
|
|
571
|
-
`readyForDisputeProtection` is true only when all three allow new protected
|
|
572
|
-
traffic. Unknown hooks, misconfigured successors, runtime-code changes,
|
|
573
|
-
dependency mismatches, and RPC failures return `mismatch` and fail closed.
|
|
574
|
-
|
|
575
|
-
An activated successor may keep its recognized predecessor policy as a
|
|
576
|
-
`DisputeNullifierRegistry` writer while that predecessor's intents drain. The
|
|
577
|
-
active state therefore requires every active writer and accepts the
|
|
578
|
-
manifest's `RecognizedPredecessorPolicy` as the only additional writer, after
|
|
579
|
-
verifying its packaged runtime hash at `asOfBlock`. Any other writer, or a
|
|
580
|
-
missing active writer, is a `mismatch`. The passive state keeps its exact
|
|
581
|
-
writer set, and an orchestrator the manifest does not list is always a
|
|
582
|
-
`mismatch`.
|
|
583
|
-
|
|
584
|
-
Dispute evidence callers should read the current attestation trust roots before
|
|
585
|
-
requesting evidence and again before submitting it:
|
|
586
|
-
|
|
587
|
-
```ts
|
|
588
|
-
const attestationConfig = await readDisputeAttestationConfig({
|
|
589
|
-
publicClient,
|
|
590
|
-
chainId: 8453,
|
|
591
|
-
environment: 'production',
|
|
592
|
-
// policyAddress: found.policyAddress, // optional known historical policy
|
|
593
|
-
});
|
|
594
|
-
|
|
595
|
-
if (attestationConfig.requiredSignatures !== 1) {
|
|
596
|
-
throw new Error('The current dispute attestation threshold is unsupported');
|
|
597
|
-
}
|
|
598
|
-
```
|
|
599
|
-
|
|
600
|
-
The helper pins the witness and threshold reads to `asOfBlock`; it does not use
|
|
601
|
-
the packaged witness set as live governance state.
|
|
602
|
-
|
|
603
|
-
`SDK_BUILD_METADATA` and the `@zkp2p/sdk/build-metadata.json` export identify
|
|
604
|
-
the SDK commit, contracts package, indexer schema package, and active manifest
|
|
605
|
-
selection hashes. A local build has the deterministic `development` identity
|
|
606
|
-
and is deliberately non-distributable, so its readiness reader returns
|
|
607
|
-
`mismatch` before making RPC calls.
|
|
608
|
-
|
|
609
|
-
For table-style liquidity UIs, the low-level `apiGetOrderbookTable()` adapter exposes curator's paginated public/private orderbook rows and row-level privacy metadata.
|
|
610
|
-
|
|
611
|
-
## Seller Credential Status
|
|
612
|
-
|
|
613
|
-
Venmo, PayPal and X Money Seller Autopilot connections use `uploadGoogleOAuthSellerCredential` for Gmail, `uploadMicrosoftOAuthSellerCredential` for personal Outlook accounts, or `uploadICloudMailSellerCredential` for iCloud Mail. The normal `uploadSellerCredential` and extension seller-capture paths support Cash App, Wise (token upload only), and Amazon Pay UPI. Existing backend Venmo cookie bundles remain usable through status/verification and low-level encrypted-bundle APIs.
|
|
130
|
+
const [best] = quote.responseObject.quotes;
|
|
614
131
|
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
});
|
|
622
|
-
```
|
|
623
|
-
|
|
624
|
-
Microsoft uses the same payment identity and adds the PKCE verifier from the authorization request:
|
|
625
|
-
|
|
626
|
-
```ts
|
|
627
|
-
await client.uploadMicrosoftOAuthSellerCredential({
|
|
628
|
-
platform: 'paypal',
|
|
629
|
-
payeeDetails: registeredMaker.hashedOnchainId,
|
|
630
|
-
payeeEmail: 'seller@example.com',
|
|
631
|
-
authorizationCode,
|
|
632
|
-
redirectUri,
|
|
633
|
-
codeVerifier,
|
|
634
|
-
});
|
|
635
|
-
```
|
|
636
|
-
|
|
637
|
-
X Money mailbox uploads require SDK 0.14.9 or later. For Gmail and Outlook, pass `platform: 'xmoney'` with the registered maker hash and the same OAuth code fields; no `payeeEmail` is needed. Enable X Money email notifications and receive a payment before connecting. The server accepts a credential only after validating a received-payment email for the registered X account. A historical receipt establishes delivery, not the current notification-setting state; keep notifications enabled for future payments. A missing or invalid receipt returns `XMONEY_EMAIL_RECEIPT_NOT_FOUND`.
|
|
638
|
-
|
|
639
|
-
Validate OAuth state in the initiating browser tab before uploading. `redirectUri` must exactly match the one in the authorization request. Both methods exchange a one-time code without retrying; start fresh consent if the response is lost. The Microsoft client secret stays server-side. See [email connection setup](../../docs/email-oauth.md).
|
|
640
|
-
|
|
641
|
-
iCloud Mail has no OAuth. Pass the seller's Apple app-specific password with the registered maker hash; PayPal also passes its receiving email, and X Money passes `payeeUsername` (normalized lowercase and checked against the maker hash). For Venmo, also supply `payeeUsername`. The SDK resolves that supplied username through anonymous `POST /v2/makers/venmo/payee-id`, rate limited (10 per 10 minutes per IP), and checks the returned numeric ID against `payeeDetails` before any mailbox work. This lookup does not expose stored maker records. Hash-only hosted signup links ask the maker for their Venmo username when connecting iCloud.
|
|
642
|
-
|
|
643
|
-
```ts
|
|
644
|
-
await client.uploadICloudMailSellerCredential({
|
|
645
|
-
platform: 'venmo',
|
|
646
|
-
payeeUsername: 'your-venmo-username',
|
|
647
|
-
payeeDetails: registeredMaker.hashedOnchainId,
|
|
648
|
-
mailboxEmail: 'seller@icloud.com',
|
|
649
|
-
appSpecificPassword,
|
|
650
|
-
});
|
|
651
|
-
```
|
|
652
|
-
|
|
653
|
-
The password is encrypted to the attested enclave and posted to the attestor paired with `baseApiUrl`. If a request to the attestor fails at the network layer, the SDK sends it once through that attestor's proxy, which serves the same enclave; the attestation is still checked against that attestor's pins. The returned bundle is verified against the pinned enclave signer, platform and maker before it is stored unchanged; the maker is not re-registered. React Native callers pass `{ attestationRuntime: { subtle, getRandomValues } }`. Failures reject with `ICloudMailCredentialError`, whose `reason` names the condition (`payee_mismatch`, `payee_not_found`, `receipt_not_found`, `app_password_rejected`, `rate_limited` with `retryAfterMs`, and so on). Apart from that fallback, the method never retries; one connection per mailbox runs at a time. `isMailboxSellerCredentialType` recognizes Gmail, Outlook and iCloud Mail credentials.
|
|
654
|
-
|
|
655
|
-
```ts
|
|
656
|
-
const status = await client.getSellerCredentialStatus({
|
|
657
|
-
processorName: 'venmo',
|
|
658
|
-
payeeDetails: '0xPAYEE_DETAILS_HASH',
|
|
659
|
-
});
|
|
660
|
-
```
|
|
661
|
-
|
|
662
|
-
`payeeDetails` is the hashed payee details bytes32 used by maker registration, quotes, and on-chain intents. The public status endpoint returns `{ platform, payeeIdHash, status, credentialType }`; maker row ids are intentionally not returned by status or upload responses.
|
|
663
|
-
|
|
664
|
-
## Signal, Fulfill, and Release Intents
|
|
665
|
-
|
|
666
|
-
```ts
|
|
667
|
-
const intentHash = await client.signalIntent({
|
|
668
|
-
depositId: 42n,
|
|
669
|
-
amount: 250_000n,
|
|
670
|
-
toAddress: '0xBuyer',
|
|
671
|
-
processorName: 'wise',
|
|
672
|
-
payeeDetails: '0xPAYEE_DETAILS_HASH',
|
|
132
|
+
const signalTxHash = await client.signalIntent({
|
|
133
|
+
depositId: BigInt(best.intent.depositId),
|
|
134
|
+
amount: best.signalIntentAmount ?? best.intent.amount,
|
|
135
|
+
toAddress: account.address,
|
|
136
|
+
processorName: best.intent.processorName,
|
|
137
|
+
payeeDetails: best.intent.payeeDetails,
|
|
673
138
|
fiatCurrencyCode: 'USD',
|
|
674
|
-
conversionRate:
|
|
675
|
-
referralFees: [
|
|
676
|
-
{ recipient: '0xPlatformFeeRecipient', fee: 2_500n },
|
|
677
|
-
{ recipient: '0xPartnerFeeRecipient', fee: 1_250n },
|
|
678
|
-
],
|
|
139
|
+
conversionRate: best.conversionRate,
|
|
679
140
|
});
|
|
680
141
|
|
|
142
|
+
// After the fiat payment, prove it with a Buyer TEE proof.
|
|
681
143
|
await client.fulfillIntent({
|
|
682
144
|
intentHash,
|
|
683
|
-
proof: {
|
|
684
|
-
proofType: 'buyerTee',
|
|
685
|
-
encryptedSessionMaterial,
|
|
686
|
-
params: buyerTeePaymentParams,
|
|
687
|
-
},
|
|
688
|
-
});
|
|
689
|
-
|
|
690
|
-
await client.releaseFundsToPayer({
|
|
691
|
-
intentHash,
|
|
692
|
-
releaseAmount: 250_000n, // the depositor releases the full intent amount
|
|
145
|
+
proof: { proofType: 'buyerTee', encryptedSessionMaterial, params },
|
|
693
146
|
});
|
|
694
147
|
```
|
|
695
148
|
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
### Signal data and deferred payouts
|
|
699
|
-
|
|
700
|
-
New intents target OrchestratorV4 when its deployment is present, otherwise
|
|
701
|
-
OrchestratorV3. Caller `data?: Hex`, `preIntentHookData` and `postIntentHook` are O3-only;
|
|
702
|
-
O4 rejects non-empty values or a nonzero hook, and O3 rejects a non-empty `payerCommitment` or a non-zero `groupId`.
|
|
703
|
-
O4 has no deposit pre-intent hooks, so escrow-only hook calls default to OrchestratorV2, and
|
|
704
|
-
`setDepositPreIntentHook` and `getDepositPreIntentHook` throw on an explicit O4 address. Its `/v3/sign` request omits `postIntentHook` and `data`.
|
|
705
|
-
O4 fulfilment contains only `paymentProof`, `intentHash`, and
|
|
706
|
-
`verificationData`; non-empty `postIntentHookData` is rejected. Existing intents resolve their original orchestrator through indexer
|
|
707
|
-
routing and on-chain reads; they keep fulfilling, cancelling and releasing there.
|
|
708
|
-
O4 intent reads, including account-intent enumeration, go through ProtocolViewerV4's
|
|
709
|
-
`getIntentV4` and `getAccountIntentsV4`, and fail closed when O4 is configured without that viewer;
|
|
710
|
-
ProtocolViewerV2 only decodes O3 and older intents. O4 intents have no `postIntentHook` or `data`;
|
|
711
|
-
they carry `payerCommitment`, `takerWhitelisted` (the taker passed the deposit's enabled whitelist at signal)
|
|
712
|
-
and `arbitrator` (of the group the taker signaled through; zero when none).
|
|
713
|
-
Use `getCurrentOrchestratorContract()` for new intents and
|
|
714
|
-
`resolveIntentOrchestrator(intentHash)` for existing ones.
|
|
715
|
-
|
|
716
|
-
`releaseFundsToPayer` takes an explicit `releaseAmount`. The depositor releases the
|
|
717
|
-
full intent amount; on O4 the intent's arbitrator may release less and the rest
|
|
718
|
-
returns to the deposit. O2/O3 take no amount and always release the full intent amount.
|
|
719
|
-
The O4 arbitrator can also `cancelIntent` and, with
|
|
720
|
-
`extendIntent({ intentHash, additionalTime })`, extend the intent's expiry for free
|
|
721
|
-
where the deposit's EscrowV2 intent guardian is O4. Older orchestrators have no
|
|
722
|
-
`extendIntent`.
|
|
723
|
-
|
|
724
|
-
Every O4 `signalIntent` struct ends with `bytes payerCommitment, bytes32 groupId`. O4
|
|
725
|
-
admits signals through its governance-selected `IntentSignalPolicy` (a zero policy
|
|
726
|
-
is ungated), which enforces the deposit whitelist and a gating signature on every
|
|
727
|
-
intent; an account may hold several open intents. Its `TakerNotWhitelisted`,
|
|
728
|
-
`SignatureExpired` and `InvalidSignature` reverts bubble out of `signalIntent`. The gating
|
|
729
|
-
signature covers O3's packed message with the raw `payerCommitment` bytes appended
|
|
730
|
-
after `chainId`; an empty commitment (`0x`, the default) leaves O3's message
|
|
731
|
-
unchanged.
|
|
732
|
-
Auto-signed O4 intents use the commitment curator returns in
|
|
733
|
-
`intentData.payerCommitment`; a missing value throws. With a caller-supplied
|
|
734
|
-
`gatingServiceSignature`, pass the `payerCommitment` it covers (default `0x`);
|
|
735
|
-
passing one without a signature throws. `groupId` (default zero) is outside the
|
|
736
|
-
signature: with the deposit whitelist enabled, a non-zero group must be allowed on
|
|
737
|
-
the deposit and have the taker as a member, and its arbitrator is recorded on the
|
|
738
|
-
intent. A stale O4 ABI fails before signing or encoding.
|
|
739
|
-
|
|
740
|
-
O3 attestation data keeps the static 448-byte UPV3 payload. UPV4 data is
|
|
741
|
-
`abi.encode(PaymentDetails, IntentSnapshot, bytes settlementData)`: the snapshot
|
|
742
|
-
ends with `payerCommitmentHash` (`keccak256` of the intent's commitment, zero when it is empty and for O3 intents)
|
|
743
|
-
and `owner` (the intent's signaler, never `to`; UPV4 rejects any other address), and
|
|
744
|
-
`settlementData = abi.encode(uint256 disputeWindow)` in seconds (0 means pay now,
|
|
745
|
-
maximum 180 days). The SDK forwards the attestor's bytes unchanged.
|
|
746
|
-
|
|
747
|
-
V2 may require stake or hold a payout when the rail default window is positive,
|
|
748
|
-
the deposit token is the vault's stake token (USDC), and the deposit+method
|
|
749
|
-
whitelist is off. Relayer takers follow the same rule as everyone else. The SDK
|
|
750
|
-
exports `DISPUTE_WINDOW_POLICY`, `getDefaultDisputeWindow` and
|
|
751
|
-
`DisputeWindowPaymentMethod` with the attestor's O4 defaults from
|
|
752
|
-
`@zkp2p/zkp2p-attestation@4.0.0-rc.1`; `4.0.0-rc.2` dropped them.
|
|
753
|
-
`mayRequireDisputeProtection({ paymentMethod, depositToken, stakeToken,
|
|
754
|
-
whitelistEnabled })` implements this quote-time rule. Venmo and PayPal default to 14 days; other supported rails default to zero. The attestor signs
|
|
755
|
-
zero for balance-funded Venmo buyer-TEE evidence or when its window config
|
|
756
|
-
switch is disabled.
|
|
757
|
-
|
|
758
|
-
Manual release, a signed zero window, or a non-stake deposit token pays now
|
|
759
|
-
without a policy record or event. With a positive window and USDC, an enabled
|
|
760
|
-
deposit+method whitelist with an allowed taker pays directly without a record
|
|
761
|
-
or policy event.
|
|
762
|
-
Otherwise the policy opens a protection. With enough free stake it locks the
|
|
763
|
-
taker's stake owner's stake; without it, O4 sends the net payout to the vault
|
|
764
|
-
(`IntentPayoutDeferred`, and `IntentFulfilled.fundsTransferredTo` is the vault) and
|
|
765
|
-
the policy funds a recipient-owned lock. Either lock is keyed by the intent hash
|
|
766
|
-
and matures at settlement time + window. `getProtection(intentHash)` keeps only
|
|
767
|
-
`{ depositor, deferredPayout, paymentMethod }`, where `deferredPayout` marks the
|
|
768
|
-
recipient-owned lock; the vault's `locks(intentHash)` holds owner, amount and
|
|
769
|
-
maturity. Release and disputes delete both.
|
|
770
|
-
Whitelist membership is recorded at signal as `Intent.takerWhitelisted`; such
|
|
771
|
-
intents and manual releases never call the policy. O4 never executes post-intent hooks.
|
|
149
|
+
`signalIntent()` returns the transaction hash; read `intentHash` from its `IntentSignaled` event. To capture the payment proof in a web app, see [Onramp Integration](https://docs.peer.xyz/developer/integrate-zkp2p/integrate-redirect-onramp).
|
|
772
150
|
|
|
773
|
-
|
|
774
|
-
const payout = await client.getPayoutStatus(intentHash);
|
|
775
|
-
const payouts = await client.getPayoutStatuses(intentHashes);
|
|
776
|
-
```
|
|
777
|
-
|
|
778
|
-
`client.getPayoutStatuses` reads each intent's indexed `IntentFulfilled`. A payout
|
|
779
|
-
sent to the packaged `stakeVaultV2` or the live stack's vault was deferred: the SDK
|
|
780
|
-
reads that vault's lock at one block and returns `HELD` before `maturesAt`,
|
|
781
|
-
`CLAIMABLE` once matured, and `RELEASED` after the lock closes. A closed lock was
|
|
782
|
-
either paid to the recipient by `release` or awarded to the depositor by a dispute;
|
|
783
|
-
on-chain state does not tell them apart. `HELD` and `CLAIMABLE` carry
|
|
784
|
-
`vault`, `recipient`, `amount` and `maturesAt`. Other fulfilments are `PAID`, and
|
|
785
|
-
intents without an indexed fulfilment are `PENDING`. A payout deferred to a vault
|
|
786
|
-
the client does not know reads as `PAID` until the package records that vault. The
|
|
787
|
-
standalone `getPayoutStatuses(publicClient, intentHashes, fulfilments, deferralVaults)`
|
|
788
|
-
takes the fulfilments and trusted vaults explicitly.
|
|
789
|
-
|
|
790
|
-
`client.parseDeferredPayoutFromLogs(logs, intentHash)` reads O4's
|
|
791
|
-
`IntentPayoutDeferred` from a successful fulfil receipt and ignores other emitters;
|
|
792
|
-
the standalone parser takes the O4 address.
|
|
793
|
-
|
|
794
|
-
O4 applies its current `settlementPolicy()` at settlement and keeps no per-intent
|
|
795
|
-
snapshot. Protection lookups search the packaged `disputeProtectionPolicyV2` and
|
|
796
|
-
the live `settlementPolicy()` read from the packaged OrchestratorV4 address. Zero
|
|
797
|
-
addresses are skipped and candidates are deduplicated; both are classified as V2.
|
|
798
|
-
A protection on two policies fails closed, and a failed read throws instead of
|
|
799
|
-
reading as unprotected. The strict current-stack checks for stake writes are
|
|
800
|
-
unchanged.
|
|
801
|
-
|
|
802
|
-
There is no `claimFor`. `release({ intentHashes })` (and its `.prepare()`) calls
|
|
803
|
-
the permissionless `DisputeProtectionPolicyV2.release(bytes32[])` on the policy
|
|
804
|
-
holding every listed protection; it reverts `NotMatured` or `ProtectionNotFound`.
|
|
805
|
-
A taker's stake lock unlocks into its owner's free stake. A deferred payout is paid
|
|
806
|
-
to its recipient (the vault's `payOutLock`), whoever sends the release, so there is
|
|
807
|
-
no withdrawal step: a follow-up `withdrawStake` for that amount would spend the
|
|
808
|
-
recipient's own free stake or revert.
|
|
809
|
-
August/O3 intents keep `releaseMaturedDisputeProtectionIntent(s)`; each method
|
|
810
|
-
rejects the other generation's intents with `ValidationError`.
|
|
151
|
+
Most write methods also have `.prepare()`, which returns `{ to, data, value, chainId }` for relayers, smart accounts, and batching. Deposits use `prepareCreateDeposit()`.
|
|
811
152
|
|
|
812
|
-
|
|
813
|
-
await client.release({ intentHashes: [intentHash] }); // the payout lands in the recipient's wallet
|
|
814
|
-
```
|
|
153
|
+
## Venmo and X Money receipt linking
|
|
815
154
|
|
|
816
|
-
`
|
|
817
|
-
`PolicyGeneration.V2` carries the open `protection` (`{ depositor, deferredPayout,
|
|
818
|
-
paymentMethod }` from `getProtection`); `PolicyGeneration.V1` retains the eight-field
|
|
819
|
-
record and six statuses.
|
|
820
|
-
`readDisputeAttestationConfig({ policyAddress })` follows either known generation.
|
|
821
|
-
|
|
822
|
-
V4 readiness and indexer APIs that list deferred payouts await the new manifest
|
|
823
|
-
and indexer schema. The retained readiness reader verifies V3 only and is not V4 readiness
|
|
824
|
-
proof. The workspace SDK version is recorded in `package.json`; local builds are not published releases.
|
|
825
|
-
|
|
826
|
-
## Extend an Intent Lifetime
|
|
827
|
-
|
|
828
|
-
The standalone `IntentGuardian` lets any payer buy more time for a live intent.
|
|
829
|
-
The fee is owner-governed, so read a fresh quote immediately before signing and
|
|
830
|
-
use `maxCost` as the payer's hard ceiling.
|
|
155
|
+
`openVenmoGmailConnect()` opens Peer's hosted page, where a seller links Gmail, personal Outlook, or iCloud Mail to a registered Venmo payee for Seller Autopilot. Your app never receives OAuth codes, passwords, tokens, or email contents. Call it directly from a click handler:
|
|
831
156
|
|
|
832
157
|
```ts
|
|
833
|
-
|
|
834
|
-
if (!policy.extensionsEnabled) {
|
|
835
|
-
throw new Error('Intent extensions are disabled');
|
|
836
|
-
}
|
|
837
|
-
|
|
838
|
-
const quote = await client.quoteIntentExtension({
|
|
839
|
-
intentAmount: 250_000n,
|
|
840
|
-
additionalTime: 60n * 60n,
|
|
841
|
-
});
|
|
842
|
-
|
|
843
|
-
const depositToken = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913';
|
|
844
|
-
const payer = walletClient.account.address;
|
|
845
|
-
const funding = await client.getIntentGuardianPayerFunding({
|
|
846
|
-
payer,
|
|
847
|
-
token: depositToken,
|
|
848
|
-
});
|
|
849
|
-
|
|
850
|
-
if (funding.balance < quote.cost) {
|
|
851
|
-
throw new Error('Insufficient token balance');
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
await client.ensureAllowance({
|
|
855
|
-
token: depositToken,
|
|
856
|
-
spender: policy.guardian,
|
|
857
|
-
amount: quote.cost,
|
|
858
|
-
});
|
|
859
|
-
|
|
860
|
-
await client.extendIntentLifetime({
|
|
861
|
-
escrow: '0xEscrow',
|
|
862
|
-
depositId: 42n,
|
|
863
|
-
intentHash,
|
|
864
|
-
additionalTime: 60n * 60n,
|
|
865
|
-
maxCost: quote.cost,
|
|
866
|
-
});
|
|
867
|
-
```
|
|
868
|
-
|
|
869
|
-
The guardian charges the target deposit's token and pays the deposit owner.
|
|
870
|
-
Extension payments are prepaid and non-refundable. `extendIntentLifetime.prepare()`
|
|
871
|
-
returns calldata without sending it.
|
|
872
|
-
|
|
873
|
-
## Deposit Access Policy
|
|
874
|
-
|
|
875
|
-
`client.accessPolicy` selects `WhitelistPolicyV2` and `AddressGroupRegistryV4`
|
|
876
|
-
with OrchestratorV4; deployed O3 uses `WhitelistPolicy` and `AddressGroupRegistry`.
|
|
877
|
-
Missing current contracts fail closed with `AccessPolicyUnsupportedError`.
|
|
878
|
-
|
|
879
|
-
WhitelistPolicyV2 applies to the entire deposit. `isEnabled` reads that flag;
|
|
880
|
-
`isGroupAllowed` checks one group. `isWhitelisted({ escrow, depositId, taker,
|
|
881
|
-
groupId? })` returns a boolean: zero group selects direct-taker admission;
|
|
882
|
-
a nonzero group requires both an allowed group and registry membership.
|
|
883
|
-
`getGroup(groupId)` includes its arbitrator, who may release part of, cancel or
|
|
884
|
-
extend an intent signaled through that group. With the whitelist disabled O4
|
|
885
|
-
accepts any taker and does not attach a group arbitrator. O3-only enumeration
|
|
886
|
-
and group-limit reads reject on V2; use point reads or indexed events instead.
|
|
887
|
-
|
|
888
|
-
Existing policies remain enforced on-chain until disabled or their deposits
|
|
889
|
-
close. `prepareDisable`, `prepareRemoveAllowedGroups` and
|
|
890
|
-
`prepareRemoveWhitelistedAddresses` retain generic V2 `setEnabled`, `setGroups`
|
|
891
|
-
and `setTakers` calls for caller-owned entries. Writes are depositor-only.
|
|
892
|
-
Callers configuring their own O4 whitelist use the V2 policy ABI with their own
|
|
893
|
-
group IDs or taker addresses; groups must exist in the fresh O4 registry.
|
|
894
|
-
|
|
895
|
-
## Referral Account API
|
|
896
|
-
|
|
897
|
-
Apps can read referral data publicly by wallet address and can write with either
|
|
898
|
-
a Privy bearer token or an EIP-712 wallet signature. Configure
|
|
899
|
-
`authorizationToken` / `getAuthorizationToken` on `Zkp2pClient` for bearer mode,
|
|
900
|
-
or use the `WithSignature` methods for wallet-only integrations.
|
|
901
|
-
|
|
902
|
-
```ts
|
|
903
|
-
const publicDashboard = await client.getReferralDashboard({
|
|
904
|
-
address: '0x1111111111111111111111111111111111111111',
|
|
905
|
-
});
|
|
906
|
-
|
|
907
|
-
const lookup = await client.lookupReferralCode('PEER42');
|
|
908
|
-
// { code, referrerWalletAddress, isActive }
|
|
909
|
-
|
|
910
|
-
const dashboard = await client.getReferralDashboard();
|
|
911
|
-
// { code, redemption, l1FeeBps, l2FeeBps, l1RefereeCount, ... }
|
|
912
|
-
|
|
913
|
-
await client.createReferralCode();
|
|
914
|
-
|
|
915
|
-
await client.redeemReferralCode('PEER42');
|
|
916
|
-
|
|
917
|
-
await client.updateReferralCode('MYCODE');
|
|
918
|
-
|
|
919
|
-
const earnings = await client.getReferralEarnings();
|
|
920
|
-
// { totalWei, l1Wei, l2Wei, unattributedWei, ... }
|
|
921
|
-
```
|
|
922
|
-
|
|
923
|
-
For external integrators without Privy, the SDK signs the curator EIP-712
|
|
924
|
-
payload with the configured `walletClient`. Production signatures default to the
|
|
925
|
-
`base_production` audience and a current Unix `issuedAt`; override `audience` for
|
|
926
|
-
non-production curator environments.
|
|
927
|
-
|
|
928
|
-
```ts
|
|
929
|
-
const { code: myCode } = await client.createReferralCodeWithSignature();
|
|
930
|
-
|
|
931
|
-
await client.redeemReferralCodeWithSignature('PEER42', {
|
|
932
|
-
referrerWalletAddress: lookup.referrerWalletAddress,
|
|
933
|
-
});
|
|
934
|
-
|
|
935
|
-
await client.updateReferralCodeWithSignature('MYCODE', {
|
|
936
|
-
oldCode: myCode,
|
|
937
|
-
});
|
|
938
|
-
```
|
|
939
|
-
|
|
940
|
-
Public `getReferralDashboard({ address })`, `getReferralEarnings({ address })`,
|
|
941
|
-
and `lookupReferralCode()` do not send auth headers. Bearer-mode dashboard reads
|
|
942
|
-
create or fetch the authenticated user's code. Signature-mode writes send exactly
|
|
943
|
-
the body shape expected by `/v2/referral/code`, `/v2/referral/redeem`, and
|
|
944
|
-
`PATCH /v2/referral/code`; codes are normalized to uppercase before signing and
|
|
945
|
-
submission.
|
|
946
|
-
|
|
947
|
-
## Prepared Transactions
|
|
948
|
-
|
|
949
|
-
Most write methods expose `.prepare(params)` and return a `PreparedTransaction` without sending the transaction. `createDeposit()` is the main exception and uses `client.prepareCreateDeposit(params)`, which returns `{ depositDetails, prepared }`. This is the stable pattern for smart accounts, batched user-ops, relayers, gas estimation, and custom senders.
|
|
950
|
-
|
|
951
|
-
```ts
|
|
952
|
-
const prepared = await client.signalIntent.prepare({
|
|
953
|
-
depositId: 42n,
|
|
954
|
-
amount: 250_000n,
|
|
955
|
-
toAddress: '0xBuyer',
|
|
956
|
-
processorName: 'wise',
|
|
957
|
-
payeeDetails: '0xPAYEE_DETAILS_HASH',
|
|
958
|
-
fiatCurrencyCode: 'USD',
|
|
959
|
-
conversionRate: 1_020_000_000_000_000_000n,
|
|
960
|
-
});
|
|
961
|
-
|
|
962
|
-
console.log(prepared);
|
|
963
|
-
// { to, data, value, chainId }
|
|
964
|
-
```
|
|
965
|
-
|
|
966
|
-
React hooks mirror this where useful. For example, `useSignalIntent()` returns `prepareSignalIntent()` and `prepared`.
|
|
967
|
-
|
|
968
|
-
## Error Handling
|
|
969
|
-
|
|
970
|
-
The SDK exports a normalized error model:
|
|
971
|
-
|
|
972
|
-
- `ZKP2PError`
|
|
973
|
-
- `ValidationError`
|
|
974
|
-
- `NetworkError`
|
|
975
|
-
- `APIError`
|
|
976
|
-
- `ContractError`
|
|
977
|
-
- `ErrorCode`
|
|
978
|
-
|
|
979
|
-
```ts
|
|
980
|
-
import { APIError, ErrorCode, ValidationError, ZKP2PError } from '@zkp2p/sdk';
|
|
158
|
+
import { openVenmoGmailConnect, VenmoGmailConnectError } from '@zkp2p/sdk';
|
|
981
159
|
|
|
982
160
|
try {
|
|
983
|
-
await
|
|
984
|
-
token: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
|
|
985
|
-
amount: 10_000_000n,
|
|
986
|
-
intentAmountRange: { min: 100_000n, max: 5_000_000n },
|
|
987
|
-
processorNames: ['wise'],
|
|
988
|
-
depositData: [{ email: 'maker@example.com' }],
|
|
989
|
-
conversionRates: [[{ currency: 'USD', conversionRate: '1020000000000000000' }]],
|
|
990
|
-
});
|
|
161
|
+
await openVenmoGmailConnect({ payeeDetails });
|
|
991
162
|
} catch (error) {
|
|
992
|
-
if (error instanceof
|
|
993
|
-
console.error('Invalid field:', error.field, error.message);
|
|
994
|
-
} else if (error instanceof APIError) {
|
|
995
|
-
console.error('HTTP status:', error.status, error.message);
|
|
996
|
-
} else if (error instanceof ZKP2PError) {
|
|
997
|
-
console.error('SDK error:', error.code ?? ErrorCode.UNKNOWN, error.details);
|
|
998
|
-
} else {
|
|
999
|
-
console.error('Unknown error:', error);
|
|
1000
|
-
}
|
|
163
|
+
if (error instanceof VenmoGmailConnectError) console.error(error.code, error.message);
|
|
1001
164
|
}
|
|
1002
165
|
```
|
|
1003
166
|
|
|
1004
|
-
|
|
167
|
+
A closed or timed-out window doesn't mean linking failed, and a return doesn't prove it worked. Read `client.getSellerCredentialStatus({ processorName: 'venmo', payeeDetails })`: the inbox is linked only when `status` is `active` and `isMailboxSellerCredentialType(credentialType)` is `true`.
|
|
1005
168
|
|
|
1006
|
-
|
|
169
|
+
`openXMoneyConnect({ payeeDetails, payeeUsername })` and `getXMoneyConnectUrl()` do the same for X Money. Cash-out apps can use `@zkp2p/cash`, which also registers the payee. See the [client reference](https://docs.peer.xyz/developer/sdk/client-reference#hosted-venmo-receipt-linking) for error codes and options.
|
|
1007
170
|
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
```ts
|
|
1011
|
-
import {
|
|
1012
|
-
getSpreadOracleConfig,
|
|
1013
|
-
resolveFiatCurrencyBytes32,
|
|
1014
|
-
resolvePaymentMethodHash,
|
|
1015
|
-
validateOracleFeedsOnChain,
|
|
1016
|
-
} from '@zkp2p/sdk';
|
|
1017
|
-
|
|
1018
|
-
const paymentMethodHash = resolvePaymentMethodHash('wise', { env: 'production' });
|
|
1019
|
-
const currencyHash = resolveFiatCurrencyBytes32('USD');
|
|
1020
|
-
const oracle = getSpreadOracleConfig('USD');
|
|
1021
|
-
|
|
1022
|
-
if (!oracle) throw new Error('No bundled oracle config for USD');
|
|
1023
|
-
|
|
1024
|
-
await client.setOracleRateConfig({
|
|
1025
|
-
depositId: 42n,
|
|
1026
|
-
paymentMethodHash,
|
|
1027
|
-
currencyHash,
|
|
1028
|
-
config: {
|
|
1029
|
-
adapter: oracle.adapter,
|
|
1030
|
-
adapterConfig: oracle.adapterConfig,
|
|
1031
|
-
spreadBps: -50,
|
|
1032
|
-
maxStaleness: oracle.maxStaleness,
|
|
1033
|
-
},
|
|
1034
|
-
});
|
|
1035
|
-
|
|
1036
|
-
await client.updateCurrencyConfigBatch({
|
|
1037
|
-
depositId: 42n,
|
|
1038
|
-
paymentMethods: [paymentMethodHash],
|
|
1039
|
-
updates: [
|
|
1040
|
-
[
|
|
1041
|
-
{
|
|
1042
|
-
code: currencyHash,
|
|
1043
|
-
minConversionRate: 1_020_000_000_000_000_000n,
|
|
1044
|
-
updateOracle: true,
|
|
1045
|
-
oracleRateConfig: {
|
|
1046
|
-
adapter: oracle.adapter,
|
|
1047
|
-
adapterConfig: oracle.adapterConfig,
|
|
1048
|
-
spreadBps: -50,
|
|
1049
|
-
maxStaleness: oracle.maxStaleness,
|
|
1050
|
-
},
|
|
1051
|
-
},
|
|
1052
|
-
],
|
|
1053
|
-
],
|
|
1054
|
-
});
|
|
1055
|
-
|
|
1056
|
-
const availableFeeds = await validateOracleFeedsOnChain(client.publicClient);
|
|
1057
|
-
console.log([...availableFeeds].sort());
|
|
1058
|
-
```
|
|
1059
|
-
|
|
1060
|
-
Useful helpers and methods in this area:
|
|
1061
|
-
|
|
1062
|
-
- `CHAINLINK_ORACLE_ADAPTER`
|
|
1063
|
-
- `PYTH_ORACLE_ADAPTER` (deprecated compatibility export)
|
|
1064
|
-
- `encodeSpreadOracleAdapterConfig`
|
|
1065
|
-
- `encodePythAdapterConfig` (deprecated compatibility helper)
|
|
1066
|
-
- `getSpreadOracleConfig`
|
|
1067
|
-
- `setOracleRateConfigBatch`
|
|
1068
|
-
- `updateCurrencyConfigBatch`
|
|
1069
|
-
- `deactivateCurrenciesBatch`
|
|
1070
|
-
|
|
1071
|
-
## Delegation and Hooks
|
|
1072
|
-
|
|
1073
|
-
```ts
|
|
1074
|
-
await client.setDelegate({
|
|
1075
|
-
depositId: 42n,
|
|
1076
|
-
delegate: '0xDelegate',
|
|
1077
|
-
});
|
|
1078
|
-
|
|
1079
|
-
await client.setRateManager({
|
|
1080
|
-
depositId: 42n,
|
|
1081
|
-
rateManagerAddress: '0xVaultAddress',
|
|
1082
|
-
rateManagerId: '0xVaultId',
|
|
1083
|
-
});
|
|
1084
|
-
|
|
1085
|
-
await client.setDepositPreIntentHook({
|
|
1086
|
-
depositId: 42n,
|
|
1087
|
-
preIntentHook: '0xHookAddress',
|
|
1088
|
-
});
|
|
1089
|
-
|
|
1090
|
-
await client.setDepositWhitelistHook({
|
|
1091
|
-
depositId: 42n,
|
|
1092
|
-
whitelistHook: '0xHookAddress',
|
|
1093
|
-
});
|
|
1094
|
-
```
|
|
1095
|
-
|
|
1096
|
-
Use `removeDelegate()` and `clearRateManager()` to unwind delegation. Hook methods are part of the current V2 surface; still validate target contract support before assuming a deployment exposes every hook.
|
|
1097
|
-
|
|
1098
|
-
## Vault / DRM
|
|
1099
|
-
|
|
1100
|
-
```ts
|
|
1101
|
-
const createHash = await client.createRateManager({
|
|
1102
|
-
config: {
|
|
1103
|
-
manager: '0xManager',
|
|
1104
|
-
feeRecipient: '0xFeeRecipient',
|
|
1105
|
-
maxFee: 50_000_000_000_000_000n,
|
|
1106
|
-
fee: 10_000_000_000_000_000n,
|
|
1107
|
-
name: 'My Vault',
|
|
1108
|
-
uri: 'ipfs://vault-metadata',
|
|
1109
|
-
},
|
|
1110
|
-
});
|
|
1111
|
-
|
|
1112
|
-
await client.setVaultFee({
|
|
1113
|
-
rateManagerId: '0xVaultId',
|
|
1114
|
-
newFee: 20_000_000_000_000_000n,
|
|
1115
|
-
});
|
|
1116
|
-
|
|
1117
|
-
await client.setVaultMinRate({
|
|
1118
|
-
rateManagerId: '0xVaultId',
|
|
1119
|
-
paymentMethodHash: resolvePaymentMethodHash('wise', { env: 'production' }),
|
|
1120
|
-
currencyHash: resolveFiatCurrencyBytes32('USD'),
|
|
1121
|
-
rate: 1_010_000_000_000_000_000n,
|
|
1122
|
-
});
|
|
1123
|
-
|
|
1124
|
-
await client.setVaultConfig({
|
|
1125
|
-
rateManagerId: '0xVaultId',
|
|
1126
|
-
newManager: '0xNewManager',
|
|
1127
|
-
newFeeRecipient: '0xNewFeeRecipient',
|
|
1128
|
-
newName: 'Updated Vault',
|
|
1129
|
-
newUri: 'ipfs://updated-vault-metadata',
|
|
1130
|
-
});
|
|
1131
|
-
```
|
|
1132
|
-
|
|
1133
|
-
## Protocol Viewer (RPC) Reads
|
|
1134
|
-
|
|
1135
|
-
ProtocolViewer methods bypass indexer lag and are the right default for primary user-facing reads.
|
|
1136
|
-
|
|
1137
|
-
```ts
|
|
1138
|
-
const deposit = await client.getPvDepositById(42n);
|
|
1139
|
-
const deposits = await client.getPvDepositsFromIds([42n, 43n]);
|
|
1140
|
-
const makerDeposits = await client.getPvAccountDeposits('0xMaker');
|
|
1141
|
-
const takerIntents = await client.getPvAccountIntents('0xTaker');
|
|
1142
|
-
const intent = await client.getPvIntent('0xIntentHash');
|
|
1143
|
-
```
|
|
1144
|
-
|
|
1145
|
-
You can also use the convenience wrappers `getDeposits()`, `getDeposit()`, `getIntents()`, and `getIntent()` for common flows.
|
|
1146
|
-
|
|
1147
|
-
## Indexer Queries
|
|
171
|
+
### Native app return
|
|
1148
172
|
|
|
1149
|
-
|
|
173
|
+
Native apps build the page URL and open it in a system browser session:
|
|
1150
174
|
|
|
1151
175
|
```ts
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
{ status: 'ACTIVE', depositor: '0xMaker' },
|
|
1155
|
-
{ limit: 25, orderBy: 'updatedAt', orderDirection: 'desc' },
|
|
1156
|
-
);
|
|
1157
|
-
const depositsWithRelations = await client.indexer.getDepositsWithRelations(
|
|
1158
|
-
{ status: 'ACTIVE' },
|
|
1159
|
-
{ limit: 10 },
|
|
1160
|
-
{ includeIntents: true },
|
|
1161
|
-
);
|
|
1162
|
-
const deposit = await client.indexer.getDepositById('8453_0xEscrowAddress_42', {
|
|
1163
|
-
includeIntents: true,
|
|
1164
|
-
});
|
|
1165
|
-
const depositsByIds = await client.indexer.getDepositsByIds(['8453_0xEscrow_42']);
|
|
1166
|
-
const depositsByIdsWithRelations = await client.indexer.getDepositsByIdsWithRelations(
|
|
1167
|
-
['8453_0xEscrow_42'],
|
|
1168
|
-
{ includeIntents: true },
|
|
1169
|
-
);
|
|
1170
|
-
const depositsByPayee = await client.indexer.getDepositsByPayeeHash('0xPayeeHash', {
|
|
1171
|
-
paymentMethodHash: '0x...',
|
|
1172
|
-
limit: 10,
|
|
1173
|
-
includeIntents: true,
|
|
1174
|
-
});
|
|
1175
|
-
|
|
1176
|
-
// Intent queries
|
|
1177
|
-
const intentsForDeposits = await client.indexer.getIntentsForDeposits(
|
|
1178
|
-
['8453_0xEscrow_42'],
|
|
1179
|
-
['SIGNALED'],
|
|
1180
|
-
);
|
|
1181
|
-
const ownerIntents = await client.indexer.getOwnerIntents('0xTaker', ['SIGNALED', 'FULFILLED']);
|
|
1182
|
-
const intentsByVault = await client.indexer.getIntentsByRateManager('0xVaultId');
|
|
1183
|
-
const intent = await client.indexer.getIntentByHash('0xIntentHash');
|
|
1184
|
-
const expiredIntents = await client.indexer.getExpiredIntents({
|
|
1185
|
-
now: BigInt(Math.floor(Date.now() / 1000)),
|
|
1186
|
-
depositIds: ['8453_0xEscrow_42'],
|
|
1187
|
-
});
|
|
1188
|
-
const fulfilledEvents = await client.indexer.getFulfilledIntentEvents(['0xIntentHash']);
|
|
1189
|
-
const fulfillment = await client.indexer.getIntentFulfillmentAmounts('0xIntentHash');
|
|
1190
|
-
const fulfillmentAndPayment = await client.indexer.getFulfillmentAndPayment('0xIntentHash');
|
|
1191
|
-
|
|
1192
|
-
// Indexed staking state. stakeOwner must come from a fresh
|
|
1193
|
-
// stakeOwnerOf(taker) read; the adapter checks it against indexed ownership.
|
|
1194
|
-
const stakingState = await client.indexer.getStakingState({
|
|
1195
|
-
chainId: 8453,
|
|
1196
|
-
environment: 'base',
|
|
1197
|
-
vaultAddress: '0xStakeVault',
|
|
1198
|
-
disputeProtectionPolicyAddress: '0xDisputeProtectionPolicy',
|
|
1199
|
-
taker: '0xTaker',
|
|
1200
|
-
stakeOwner: '0xEffectiveStakeOwner',
|
|
1201
|
-
});
|
|
1202
|
-
|
|
1203
|
-
// Received USDC:
|
|
1204
|
-
// - fulfilledEvents[0].amount is the net USDC transferred to the taker.
|
|
1205
|
-
// - fulfillment.takerAmountNetFees is the same net taker amount from the Intent row.
|
|
1206
|
-
// - fulfillment.releasedAmount is gross USDC released from the deposit before fees.
|
|
1207
|
-
|
|
1208
|
-
// Fund activity and snapshots
|
|
1209
|
-
const fundActivities = await client.indexer.getDepositFundActivities('8453_0xEscrowAddress_42');
|
|
1210
|
-
const makerActivities = await client.indexer.getMakerFundActivities('0xMaker', 50);
|
|
1211
|
-
const snapshots = await client.indexer.getDepositDailySnapshots('8453_0xEscrowAddress_42', 30);
|
|
1212
|
-
const profitSnapshots = await client.indexer.getProfitSnapshotsByDeposits(['8453_0xEscrow_42']);
|
|
1213
|
-
|
|
1214
|
-
// Rate manager (vault) queries
|
|
1215
|
-
const managers = await client.indexer.getRateManagers({
|
|
1216
|
-
limit: 10,
|
|
1217
|
-
orderBy: 'currentDelegatedBalance',
|
|
1218
|
-
orderDirection: 'desc',
|
|
1219
|
-
});
|
|
1220
|
-
const managerDetail = await client.indexer.getRateManagerDetail('0xVaultId', {
|
|
1221
|
-
rateManagerAddress: '0xVaultAddress',
|
|
1222
|
-
statsLimit: 30,
|
|
1223
|
-
});
|
|
1224
|
-
const delegations = await client.indexer.getRateManagerDelegations('0xVaultId');
|
|
1225
|
-
const delegation = await client.indexer.getDelegationForDeposit('8453_0xEscrow_42');
|
|
1226
|
-
const managerSnapshots = await client.indexer.getManagerDailySnapshots('0xVaultId');
|
|
1227
|
-
const manualRates = await client.indexer.getManualRateUpdates('0xVaultId');
|
|
1228
|
-
const oracleUpdates = await client.indexer.getOracleConfigUpdates('0xVaultId');
|
|
1229
|
-
|
|
1230
|
-
// Raw GraphQL
|
|
1231
|
-
const custom = await client.indexer.query<MyType>({
|
|
1232
|
-
query: '{ deposits(limit: 5) { id } }',
|
|
1233
|
-
});
|
|
1234
|
-
```
|
|
1235
|
-
|
|
1236
|
-
## React Hooks
|
|
1237
|
-
|
|
1238
|
-
Install React and import hooks from `@zkp2p/sdk/react`. React is an optional peer dependency of the SDK.
|
|
1239
|
-
|
|
1240
|
-
Most mutation hooks return a named action plus status fields such as `isLoading`, `error`, and `txHash`. Hooks with prepare support expose dedicated `prepare...` helpers, and some of them also store the latest `prepared` transaction in hook state. Every hook exports a matching `Use*Options` type.
|
|
1241
|
-
|
|
1242
|
-
```tsx
|
|
1243
|
-
import {
|
|
1244
|
-
useCreateDeposit,
|
|
1245
|
-
useSignalIntent,
|
|
1246
|
-
useExtendIntentLifetime,
|
|
1247
|
-
useSetDisputeProtectionEnabled,
|
|
1248
|
-
useCreateVault,
|
|
1249
|
-
useVaultDelegation,
|
|
1250
|
-
} from '@zkp2p/sdk/react';
|
|
1251
|
-
|
|
1252
|
-
const createDeposit = useCreateDeposit({ client });
|
|
1253
|
-
const signalIntent = useSignalIntent({ client });
|
|
1254
|
-
const extendIntent = useExtendIntentLifetime({ client });
|
|
1255
|
-
const disputeProtection = useSetDisputeProtectionEnabled({ client });
|
|
1256
|
-
const createVault = useCreateVault({ client, sendTransaction });
|
|
1257
|
-
const vaultDelegation = useVaultDelegation({ client, sendTransaction, sendBatch });
|
|
1258
|
-
```
|
|
1259
|
-
|
|
1260
|
-
Hook groups:
|
|
1261
|
-
|
|
1262
|
-
- Deposit lifecycle: `useCreateDeposit`, `useAddFunds`, `useRemoveFunds`, `useWithdrawDeposit`, `useSetAcceptingIntents`, `useSetIntentRange`, `useSetCurrencyMinRate`, `useSetRetainOnEmpty`, `useSetDisputeProtectionEnabled`
|
|
1263
|
-
- Payment and currency management: `useAddPaymentMethods`, `useRemovePaymentMethod`, `useSetPaymentMethodActive`, `useAddCurrencies`, `useRemoveCurrency`, `useDeactivateCurrency`
|
|
1264
|
-
- Intent lifecycle: `useSignalIntent`, `useFulfillIntent`, `useReleaseFundsToPayer`, `usePruneExpiredIntents`, `useExtendIntentLifetime`
|
|
1265
|
-
- Delegation: `useSetDelegate`, `useRemoveDelegate`
|
|
1266
|
-
- Vault / DRM: `useCreateVault`, `useVaultDelegation`, `useSetVaultFee`, `useSetVaultMinRate`, `useSetVaultConfig`
|
|
1267
|
-
|
|
1268
|
-
`useVaultDelegation()` is the batching-oriented hook. It returns `delegateDeposit`, `delegateDeposits`, `clearDelegation`, and `clearDelegations`.
|
|
1269
|
-
|
|
1270
|
-
## Contracts and Catalog Helpers
|
|
176
|
+
import { getVenmoGmailConnectUrl } from '@zkp2p/sdk';
|
|
177
|
+
import * as WebBrowser from 'expo-web-browser';
|
|
1271
178
|
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
getOrchestratorV3Contract,
|
|
1277
|
-
getPaymentMethodsCatalog,
|
|
1278
|
-
getRateManagerContracts,
|
|
1279
|
-
getDisputeProtectionPolicyContract,
|
|
1280
|
-
getStakeVaultContract,
|
|
1281
|
-
RISK_POSITION_SETTLED_EVENT_ABI,
|
|
1282
|
-
resolveFiatCurrencyBytes32,
|
|
1283
|
-
resolvePaymentMethodHash,
|
|
1284
|
-
} from '@zkp2p/sdk';
|
|
1285
|
-
|
|
1286
|
-
const contracts = getContracts(8453, 'production');
|
|
1287
|
-
const rateManagerContracts = getRateManagerContracts(8453, 'production');
|
|
1288
|
-
const stakeVault = getStakeVaultContract(8453, 'staging');
|
|
1289
|
-
const orchestratorV3 = getOrchestratorV3Contract(8453, 'staging');
|
|
1290
|
-
const disputeProtectionPolicy = getDisputeProtectionPolicyContract(8453, 'staging');
|
|
1291
|
-
const paymentMethods = getPaymentMethodsCatalog(8453, 'production');
|
|
1292
|
-
const usdHash = resolveFiatCurrencyBytes32('USD');
|
|
1293
|
-
const wiseHash = resolvePaymentMethodHash('wise', { env: 'production' });
|
|
179
|
+
const returnUrl = 'partner-app://venmo-linked'; // a scheme registered in your app binary
|
|
180
|
+
const connectUrl = getVenmoGmailConnectUrl({ payeeDetails, returnUrl });
|
|
181
|
+
await WebBrowser.openAuthSessionAsync(connectUrl, returnUrl);
|
|
182
|
+
// Check the credential status after return or dismissal.
|
|
1294
183
|
```
|
|
1295
184
|
|
|
1296
|
-
|
|
185
|
+
After a successful link, the page opens `returnUrl` unchanged; it adds no codes, tokens, or status. Without `returnUrl`, the page tries to close itself. Without the SDK, build the URL as `https://app.peer.xyz/connect/venmo?returnUrl=<URL-encoded callback>#<payeeDetails>`.
|
|
1297
186
|
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
`AED`, `ARS`, `AUD`, `BRL`, `CAD`, `CHF`, `CNY`, `CZK`, `DKK`, `EUR`, `GBP`, `HKD`, `HUF`, `IDR`, `ILS`, `INR`, `JPY`, `KES`, `MXN`, `MYR`, `NOK`, `NZD`, `PHP`, `PLN`, `RON`, `SAR`, `SEK`, `SGD`, `THB`, `TRY`, `UGX`, `USD`, `VND`, `ZAR`
|
|
1301
|
-
|
|
1302
|
-
## Supported Payment Platforms
|
|
1303
|
-
|
|
1304
|
-
`wise`, `venmo`, `revolut`, `cashapp`, `mercadopago`, `zelle`, `paypal`, `monzo`, `chime`, `luxon`, `n26`, `alipay`, `xmoney`
|
|
1305
|
-
|
|
1306
|
-
## Attribution (ERC-8021)
|
|
187
|
+
### Popup customization
|
|
1307
188
|
|
|
1308
|
-
|
|
189
|
+
Pass `appearance` to any of the hosted-page helpers, and `popup` to the browser openers:
|
|
1309
190
|
|
|
1310
191
|
```ts
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
192
|
+
await openVenmoGmailConnect({
|
|
193
|
+
payeeDetails,
|
|
194
|
+
popup: { width: 500, height: 620 },
|
|
195
|
+
appearance: {
|
|
196
|
+
logoUrl: 'https://your-app.example/logo.png',
|
|
197
|
+
logoAlt: 'Your app',
|
|
198
|
+
backgroundColor: '#FFFFFF',
|
|
199
|
+
textColor: '#172033',
|
|
200
|
+
buttonColor: '#6246EA',
|
|
201
|
+
buttonTextColor: '#FFFFFF',
|
|
202
|
+
fontFamily: 'Arial, sans-serif',
|
|
203
|
+
buttonBorderRadius: 24,
|
|
1321
204
|
},
|
|
1322
205
|
});
|
|
1323
206
|
```
|
|
1324
207
|
|
|
1325
|
-
`
|
|
1326
|
-
Peer deposit-level referral attribution, using the same `peer-ref-XXXXXX` marker
|
|
1327
|
-
as the Cash SDK:
|
|
208
|
+
Colors take `#RGB` or `#RRGGBB`: `backgroundColor`, `cardBackgroundColor`, `textColor`, `secondaryTextColor`, `buttonColor`, `buttonTextColor`, `buttonHoverColor`, `focusColor`, `borderColor`, `successColor`, `errorColor`, `logoBackgroundColor`, and `logoBorderColor`.
|
|
1328
209
|
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
210
|
+
| Option | Accepted values |
|
|
211
|
+
| --------------------------------------------- | ----------------------------------------------------- |
|
|
212
|
+
| `fontSize` | 12 to 24 px |
|
|
213
|
+
| `headingFontSize` | 20 to 48 px |
|
|
214
|
+
| `buttonBorderRadius`, `cardBorderRadius` | 0 to 40 px |
|
|
215
|
+
| `buttonHeight` | 44 to 80 px |
|
|
216
|
+
| `contentWidth` | 280 to 960 px |
|
|
217
|
+
| `padding` | 16 to 64 px |
|
|
218
|
+
| `gap` | 12 to 48 px |
|
|
219
|
+
| `logoHeight` | 24 to 80 px |
|
|
220
|
+
| `fontFamily`, `headingFontFamily` | A font-family list |
|
|
221
|
+
| `fontUrl` | A hosted WOFF or WOFF2 file; its host must allow CORS |
|
|
222
|
+
| `logoUrl`, `logoAlt` | Your logo URL and its alt text (up to 80 characters) |
|
|
223
|
+
| `headingTextTransform`, `buttonTextTransform` | `none` or `uppercase` |
|
|
1336
224
|
|
|
1337
|
-
|
|
1338
|
-
are uppercased. Invalid codes reject before payee registration or transaction
|
|
1339
|
-
submission. The resulting ERC-8021 codes are `peer-ref-ABC123`, `my-app`, then
|
|
1340
|
-
`bc_nbn6qkni`. Omitting `referralCode` preserves existing attribution. The SDK does
|
|
1341
|
-
not add the Cash-specific `peer-cash` source marker.
|
|
225
|
+
`popup` takes `width` from 320 to 1200 px and `height` from 480 to 1600 px; the default is 500 by 700. Mobile browsers open a tab instead. Asset URLs must use HTTPS, except on `localhost`. Invalid options throw `ValidationError` before the window opens. Google and Microsoft consent screens keep their own styling.
|
|
1342
226
|
|
|
1343
|
-
|
|
1344
|
-
this option does not set a fee or redeem a maker referral. Ordinary
|
|
1345
|
-
`txOverrides.referrer` codes remain analytics attribution. When `referralCode` is
|
|
1346
|
-
supplied, an existing `peer-ref-` marker in `txOverrides.referrer` is rejected
|
|
1347
|
-
before side effects, including an identical marker. Supply the referral through
|
|
1348
|
-
one option only; Curator treats conflicting referral attribution as ambiguous.
|
|
227
|
+
## Deposit access policy
|
|
1349
228
|
|
|
1350
|
-
|
|
229
|
+
`client.accessPolicy` reads deposit whitelists and prepares the depositor's transactions to turn a whitelist off or remove entries. See the [client reference](https://docs.peer.xyz/developer/sdk/client-reference#deposit-access-policy).
|
|
1351
230
|
|
|
1352
|
-
##
|
|
231
|
+
## React hooks
|
|
1353
232
|
|
|
1354
|
-
|
|
233
|
+
```tsx
|
|
234
|
+
import { useSignalIntent } from '@zkp2p/sdk/react';
|
|
1355
235
|
|
|
1356
|
-
|
|
1357
|
-
pnpm --filter @zkp2p/sdk docs
|
|
236
|
+
const { signalIntent, prepareSignalIntent, isLoading, error, txHash } = useSignalIntent({ client });
|
|
1358
237
|
```
|
|
1359
238
|
|
|
1360
|
-
|
|
239
|
+
Hooks cover deposits, intents, payment methods, currencies, delegation, vaults, and intent lifetime extension. See [React Hooks](https://docs.peer.xyz/developer/sdk/react-hooks).
|
|
1361
240
|
|
|
1362
|
-
##
|
|
241
|
+
## Errors and logging
|
|
1363
242
|
|
|
1364
|
-
|
|
243
|
+
SDK errors extend `ZKP2PError` (`ValidationError`, `NetworkError`, `APIError`, and `ContractError`) and carry a `code`. Call `setLogLevel('debug')` for verbose logs.
|
|
1365
244
|
|
|
1366
|
-
|
|
1367
|
-
import { setLogLevel } from '@zkp2p/sdk';
|
|
245
|
+
## Documentation
|
|
1368
246
|
|
|
1369
|
-
|
|
1370
|
-
|
|
247
|
+
- [SDK overview](https://docs.peer.xyz/developer/sdk)
|
|
248
|
+
- [Client reference](https://docs.peer.xyz/developer/sdk/client-reference)
|
|
249
|
+
- [React hooks](https://docs.peer.xyz/developer/sdk/react-hooks)
|
|
250
|
+
- [Offramp integration](https://docs.peer.xyz/developer/offramp)
|
|
251
|
+
- [Onramp integration](https://docs.peer.xyz/developer/integrate-zkp2p/integrate-redirect-onramp)
|
|
252
|
+
- [React Native SDK](https://docs.peer.xyz/developer/sdk/react-native)
|
|
1371
253
|
|
|
1372
|
-
|
|
254
|
+
## Publishing
|
|
1373
255
|
|
|
1374
|
-
|
|
256
|
+
Maintainers bump the version and changelog in a PR, merge to `main`, then run
|
|
257
|
+
`gh workflow run publish-sdk.yml --ref main -f version=X.Y.Z` and verify the run
|
|
258
|
+
and npm tags. Publication uses GitHub OIDC in `npm-publish`; local `npm publish`
|
|
259
|
+
is rejected by npm. See [PUBLISHING.md](PUBLISHING.md) for setup, prerelease tags,
|
|
260
|
+
and human passkey-2FA promotion of existing versions.
|
|
1375
261
|
|
|
1376
|
-
|
|
1377
|
-
cd packages/sdk
|
|
1378
|
-
pnpm build
|
|
1379
|
-
pnpm test
|
|
1380
|
-
pnpm typecheck
|
|
1381
|
-
pnpm lint
|
|
1382
|
-
pnpm docs
|
|
1383
|
-
```
|
|
262
|
+
## License
|
|
1384
263
|
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
- NPM: https://www.npmjs.com/package/@zkp2p/sdk
|
|
1388
|
-
- Docs: https://docs.peer.xyz
|
|
1389
|
-
- Monorepo: https://github.com/zkp2p/zkp2p-clients
|
|
1390
|
-
- TypeDoc output: `packages/sdk/docs` (generated locally by `pnpm --filter @zkp2p/sdk docs`)
|
|
1391
|
-
|
|
1392
|
-
### Amazon Pay UPI seller credentials
|
|
1393
|
-
|
|
1394
|
-
Use `platform: 'upi'` with `callerAddress` and `sessionMaterial: { sessionCookie, userAgent }` in the private extension runtime. Omit `payeeId` and `offchainId` when creating the bundle: the attestor derives the receiving VPA from Amazon's current QR. `getAmazonPaySellerIdentity(bundle)` reads that returned identity; storage registers that exact VPA and checks its maker hash against the sealed bundle. Never expose session material to the requesting page.
|
|
1395
|
-
|
|
1396
|
-
Amazon capture requires extension 0.6.8 or later. Staging SAR uses the trusted staging attestor and staging provider templates; production requires its Amazon template and backend rollout. This source change does not publish either package or extension.
|
|
1397
|
-
|
|
1398
|
-
### Historical dispute policy lookup
|
|
1399
|
-
|
|
1400
|
-
`findDisputeProtectionIntent({ publicClient, chainId, environment?, intentHash,
|
|
1401
|
-
blockNumber? })` uses RPC only; `environment` defaults to `production` and an
|
|
1402
|
-
omitted `blockNumber` uses `publicClient.getBlockNumber()`. At that block it reads
|
|
1403
|
-
O4's live `settlementPolicy()` and queries the packaged V2 policy, the live O4
|
|
1404
|
-
policy, then the known V1 policies (packaged canonical and bypass, manifest, and
|
|
1405
|
-
recognized predecessor), skipping zero addresses and deduplicating in that order.
|
|
1406
|
-
V2 candidates use `getProtection`; V1 candidates use `getDisputeProtectionIntent`.
|
|
1407
|
-
The first nonzero-depositor V2 protection or non-`None` V1 intent wins. Multiple
|
|
1408
|
-
V2 protections for the same hash throw. A found record is returned even if another
|
|
1409
|
-
policy read fails; with no record, any failed or malformed read throws. It returns
|
|
1410
|
-
`null` when no policies exist or every read successfully reports no record.
|
|
1411
|
-
|
|
1412
|
-
The result is `{ generation: PolicyGeneration.V2, policyAddress, protection }`,
|
|
1413
|
-
where `protection` is `{ depositor, deferredPayout, paymentMethod }`, or
|
|
1414
|
-
`{ generation: PolicyGeneration.V1, policyAddress, intent }`, where `intent` is
|
|
1415
|
-
the eight-field V1 record with its six-status enum.
|
|
1416
|
-
All calls share a block. Use the returned policy for dispute submission and
|
|
1417
|
-
`readDisputeAttestationConfig({ publicClient, chainId, environment, policyAddress })`.
|
|
1418
|
-
For a known non-manifest policy, the latter follows `disputeVerifier()` and
|
|
1419
|
-
`attestationVerifier()` before reading witnesses and threshold at one block.
|
|
1420
|
-
Unknown policies throw. Omitting `policyAddress` preserves manifest behavior.
|
|
264
|
+
MIT
|