@provex/proving 1.8.0 → 1.9.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/dist/{chunk-LFDS3XGK.js → chunk-OSBIXUFA.js} +46 -11
- package/dist/chunk-OSBIXUFA.js.map +1 -0
- package/dist/index.cjs +64 -105
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +157 -5
- package/dist/index.d.ts +157 -5
- package/dist/index.js +75 -3
- package/dist/index.js.map +1 -1
- package/dist/{types-ByiBb7AN.d.ts → useProving-h4RtlSEU.d.cts} +98 -1
- package/dist/{types-ByiBb7AN.d.cts → useProving-h4RtlSEU.d.ts} +98 -1
- package/dist/useProving.cjs +43 -8
- package/dist/useProving.cjs.map +1 -1
- package/dist/useProving.d.cts +3 -90
- package/dist/useProving.d.ts +3 -90
- package/dist/useProving.js +1 -1
- package/package.json +2 -8
- package/dist/adapters/extensionEnclave.cjs +0 -160
- package/dist/adapters/extensionEnclave.cjs.map +0 -1
- package/dist/adapters/extensionEnclave.d.cts +0 -5
- package/dist/adapters/extensionEnclave.d.ts +0 -5
- package/dist/adapters/extensionEnclave.js +0 -3
- package/dist/adapters/extensionEnclave.js.map +0 -1
- package/dist/chunk-LFDS3XGK.js.map +0 -1
- package/dist/chunk-QLPNUQDA.js +0 -157
- package/dist/chunk-QLPNUQDA.js.map +0 -1
- package/dist/extensionEnclave-BjxXsuaj.d.cts +0 -119
- package/dist/extensionEnclave-DLCjCWxT.d.ts +0 -119
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,82 @@
|
|
|
1
|
-
|
|
2
|
-
export { c as CaptureAdapter, C as CaptureCandidate, b as CaptureHandle, a as CaptureRequest, E as EnclaveCaptureUnavailable, M as ManualSelectionRequired, P as ProvingIntent, d as ProvingRequest, e as ProvingState, S as SelectTransaction, V as VerifiedAttestation } from './types-ByiBb7AN.cjs';
|
|
1
|
+
import { Hex } from 'viem';
|
|
3
2
|
import { V3AttestationResponseObject } from '@provex/utils';
|
|
3
|
+
import { S as SelectTransaction, C as CaptureCandidate, a as CaptureRequest } from './useProving-h4RtlSEU.cjs';
|
|
4
|
+
export { c as CaptureAdapter, b as CaptureHandle, E as EnclaveCaptureUnavailable, M as ManualSelectionRequired, f as ProvingClient, P as ProvingIntent, d as ProvingRequest, e as ProvingState, U as UseProvingOptions, g as UseProvingReturn, V as VerifiedAttestation, u as useProving } from './useProving-h4RtlSEU.cjs';
|
|
4
5
|
import { TokenInfo } from '@provex/utils/tokens';
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
import { SubProviderKey, ProviderKey } from '@provex/utils/payment';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @fileoverview Buyer trusted-execution attestation client.
|
|
10
|
+
*
|
|
11
|
+
* In PeerAuth extension 0.5.2+, capture produces a buyerTee proof —
|
|
12
|
+
* `{ proofType: 'buyerTee', encryptedSessionMaterial, params }` — where the
|
|
13
|
+
* bank session is already encrypted toward the enclave (cookies never reach
|
|
14
|
+
* our page in plaintext). Instead of re-signing a Reclaim proof through our
|
|
15
|
+
* gate, we hand that material to zkp2p's trusted-execution attestation
|
|
16
|
+
* service, which verifies the payment inside an Amazon Web Services Nitro
|
|
17
|
+
* enclave and signs the attestation directly.
|
|
18
|
+
*
|
|
19
|
+
* The response `responseObject` is the same `V3AttestationResponseObject`
|
|
20
|
+
* shape our gate returns, so it flows through the existing
|
|
21
|
+
* `encodeV3PaymentProof` path unchanged.
|
|
22
|
+
*
|
|
23
|
+
* Moved verbatim from `@provex/ui` (packages/ui/src/lib/buyerTeeAttestation.ts)
|
|
24
|
+
* with the base URL changed from a `@provex/ui` config import to an injected
|
|
25
|
+
* `attestationBaseUrl` argument so this package carries no `@provex/ui` dep.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Runtime shape of a buyerTee proof emitted by the PeerAuth extension.
|
|
30
|
+
* Narrow with {@link asBuyerTeeProof} before use.
|
|
31
|
+
*/
|
|
32
|
+
interface BuyerTeeProof {
|
|
33
|
+
proofType: 'buyerTee';
|
|
34
|
+
/** Session material already encrypted toward the enclave (opaque to us). */
|
|
35
|
+
encryptedSessionMaterial: string;
|
|
36
|
+
/** Platform-specific params, e.g. Revolut `{ index }`, Chase `{ index }`. */
|
|
37
|
+
params: unknown;
|
|
38
|
+
actionType?: string;
|
|
39
|
+
actionPlatform?: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Narrow an extension proof to a buyerTee proof, or null when it is the
|
|
43
|
+
* legacy Reclaim shape (or malformed).
|
|
44
|
+
*/
|
|
45
|
+
declare function asBuyerTeeProof(proof: unknown): BuyerTeeProof | null;
|
|
46
|
+
/** Intent details the enclave binds the attestation to. */
|
|
47
|
+
interface BuyerTeeIntent {
|
|
48
|
+
intentHash: Hex;
|
|
49
|
+
amount: string;
|
|
50
|
+
timestampMs: string;
|
|
51
|
+
paymentMethod: Hex;
|
|
52
|
+
fiatCurrency: Hex;
|
|
53
|
+
conversionRate: string;
|
|
54
|
+
payeeDetails: Hex;
|
|
55
|
+
timestampBufferMs?: string;
|
|
56
|
+
}
|
|
57
|
+
interface RequestBuyerTeeAttestationArgs {
|
|
58
|
+
/** Gate/attestation origin (was `gateForwarderBaseUrl` in @provex/ui). */
|
|
59
|
+
attestationBaseUrl: string;
|
|
60
|
+
/** Extension platform / bank key, e.g. `revolut`, `chase`. */
|
|
61
|
+
platform: string;
|
|
62
|
+
/** Action type, e.g. `transfer_revolut`, `transfer_zelle`. */
|
|
63
|
+
actionType: string;
|
|
64
|
+
/** Encrypted session material from the buyerTee capture. */
|
|
65
|
+
encryptedSessionMaterial: string;
|
|
66
|
+
/** Platform params from the capture (e.g. `{ index }`). */
|
|
67
|
+
params: unknown;
|
|
68
|
+
/** PulseChain UnifiedPaymentVerifier the gate re-signs the attestation for. */
|
|
69
|
+
verifyingContract: string;
|
|
70
|
+
intent: BuyerTeeIntent;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Verify a buyer payment via the gate. The gate proxies the encrypted capture
|
|
74
|
+
* to zkp2p's enclave, then re-signs the resulting attestation for PulseChain
|
|
75
|
+
* with our witness key — the enclave itself refuses to sign for 369.
|
|
76
|
+
*
|
|
77
|
+
* Throws with the gate's error text on a non-2xx response.
|
|
78
|
+
*/
|
|
79
|
+
declare function requestBuyerTeeAttestation(args: RequestBuyerTeeAttestationArgs): Promise<V3AttestationResponseObject>;
|
|
7
80
|
|
|
8
81
|
/**
|
|
9
82
|
* @fileoverview Pure proving derivations moved from @provex/ui
|
|
@@ -46,4 +119,83 @@ declare function computePartialFulfillment({ attestation, intentAmount, conversi
|
|
|
46
119
|
feeBps: bigint | null | undefined;
|
|
47
120
|
}): PartialFulfillment | null;
|
|
48
121
|
|
|
49
|
-
|
|
122
|
+
interface ManualTransactionSelect {
|
|
123
|
+
/**
|
|
124
|
+
* Resolver injected into useProving — the enclave adapter calls this when
|
|
125
|
+
* auto-match of the bank transaction fails (extensionEnclave.ts:189-190).
|
|
126
|
+
*/
|
|
127
|
+
selectTransaction: SelectTransaction;
|
|
128
|
+
/**
|
|
129
|
+
* Non-null while the adapter is awaiting a pick; drives the
|
|
130
|
+
* TransactionSelector rendered inside GenerateProofStep.
|
|
131
|
+
*/
|
|
132
|
+
candidates: CaptureCandidate[] | null;
|
|
133
|
+
/**
|
|
134
|
+
* Called by TransactionSelector with the chosen candidate's originalIndex.
|
|
135
|
+
* Resolves the pending promise and resets candidates to null.
|
|
136
|
+
*/
|
|
137
|
+
pick: (originalIndex: number) => void;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Bridge the framework-agnostic {@link SelectTransaction} resolver the enclave
|
|
141
|
+
* adapter expects (extensionEnclave.ts:189-190) to React state the
|
|
142
|
+
* GenerateProofStep TransactionSelector can render.
|
|
143
|
+
*
|
|
144
|
+
* The adapter awaits the promise returned by `selectTransaction`; the user's
|
|
145
|
+
* call to `pick` resolves it with the chosen `originalIndex`.
|
|
146
|
+
*
|
|
147
|
+
* `useRef` is justified here exclusively for holding the pending promise
|
|
148
|
+
* resolver across renders without triggering a re-render cycle — the single
|
|
149
|
+
* sanctioned use per the react-state-preferences memory.
|
|
150
|
+
*/
|
|
151
|
+
declare function useManualTransactionSelect(): ManualTransactionSelect;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* @fileoverview Pure builder that assembles a {@link CaptureRequest} from
|
|
155
|
+
* resolved order data.
|
|
156
|
+
*
|
|
157
|
+
* Hoisted verbatim from the intent-assembly block in SubmitStep.tsx:312-342
|
|
158
|
+
* so the mapping is unit-tested in isolation and reusable by the proving shell.
|
|
159
|
+
*
|
|
160
|
+
* Monetary values stay bigint in base units through the entire call stack;
|
|
161
|
+
* this is the single boundary where they are stringified for the attestor
|
|
162
|
+
* wire format.
|
|
163
|
+
*/
|
|
164
|
+
|
|
165
|
+
/** All resolved order fields required to build a {@link CaptureRequest}. */
|
|
166
|
+
interface BuildCaptureRequestInput {
|
|
167
|
+
/** On-chain intent hash. */
|
|
168
|
+
intentHash: Hex;
|
|
169
|
+
/** Chain the intent lives on. */
|
|
170
|
+
chainId: number;
|
|
171
|
+
/** Bank-level sub-provider, e.g. `'zelle-chase'`, or `null` for top-level providers. */
|
|
172
|
+
subProvider: SubProviderKey | null;
|
|
173
|
+
/** Provider key from the deposit. May itself be a sub-provider key (contains a dash). */
|
|
174
|
+
providerKey: ProviderKey | SubProviderKey;
|
|
175
|
+
/** Address of the UnifiedPaymentVerifier contract for this chain. */
|
|
176
|
+
verifyingContract: Hex;
|
|
177
|
+
/** payeeDetailsHash from the matched verifier record. */
|
|
178
|
+
payeeDetailsHash: Hex;
|
|
179
|
+
/** Settlement token for this intent (used by the adapter for amount conversion). */
|
|
180
|
+
token: TokenInfo;
|
|
181
|
+
/** Resolved intent fields, monetary values in bigint base units. */
|
|
182
|
+
intent: {
|
|
183
|
+
amount: bigint;
|
|
184
|
+
timestamp: bigint;
|
|
185
|
+
paymentMethod: Hex | undefined;
|
|
186
|
+
fiatCurrency: Hex;
|
|
187
|
+
conversionRate: bigint;
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Build the {@link CaptureRequest} from resolved order data.
|
|
192
|
+
*
|
|
193
|
+
* Pure hoist of the intent-assembly block in SubmitStep.tsx:312-342.
|
|
194
|
+
* No side effects, no I/O, no React. Safe to call in any environment.
|
|
195
|
+
*
|
|
196
|
+
* @param input - All resolved order fields needed to build the request.
|
|
197
|
+
* @returns A fully-formed {@link CaptureRequest} ready for a {@link CaptureAdapter}.
|
|
198
|
+
*/
|
|
199
|
+
declare function buildCaptureRequest(input: BuildCaptureRequestInput): CaptureRequest;
|
|
200
|
+
|
|
201
|
+
export { type BuildCaptureRequestInput, type BuyerTeeIntent, type BuyerTeeProof, CaptureCandidate, CaptureRequest, type ManualTransactionSelect, type PartialFulfillment, type RequestBuyerTeeAttestationArgs, SelectTransaction, asBuyerTeeProof, buildCaptureRequest, computePartialFulfillment, requestBuyerTeeAttestation, useManualTransactionSelect };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,82 @@
|
|
|
1
|
-
|
|
2
|
-
export { c as CaptureAdapter, C as CaptureCandidate, b as CaptureHandle, a as CaptureRequest, E as EnclaveCaptureUnavailable, M as ManualSelectionRequired, P as ProvingIntent, d as ProvingRequest, e as ProvingState, S as SelectTransaction, V as VerifiedAttestation } from './types-ByiBb7AN.js';
|
|
1
|
+
import { Hex } from 'viem';
|
|
3
2
|
import { V3AttestationResponseObject } from '@provex/utils';
|
|
3
|
+
import { S as SelectTransaction, C as CaptureCandidate, a as CaptureRequest } from './useProving-h4RtlSEU.js';
|
|
4
|
+
export { c as CaptureAdapter, b as CaptureHandle, E as EnclaveCaptureUnavailable, M as ManualSelectionRequired, f as ProvingClient, P as ProvingIntent, d as ProvingRequest, e as ProvingState, U as UseProvingOptions, g as UseProvingReturn, V as VerifiedAttestation, u as useProving } from './useProving-h4RtlSEU.js';
|
|
4
5
|
import { TokenInfo } from '@provex/utils/tokens';
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
import { SubProviderKey, ProviderKey } from '@provex/utils/payment';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @fileoverview Buyer trusted-execution attestation client.
|
|
10
|
+
*
|
|
11
|
+
* In PeerAuth extension 0.5.2+, capture produces a buyerTee proof —
|
|
12
|
+
* `{ proofType: 'buyerTee', encryptedSessionMaterial, params }` — where the
|
|
13
|
+
* bank session is already encrypted toward the enclave (cookies never reach
|
|
14
|
+
* our page in plaintext). Instead of re-signing a Reclaim proof through our
|
|
15
|
+
* gate, we hand that material to zkp2p's trusted-execution attestation
|
|
16
|
+
* service, which verifies the payment inside an Amazon Web Services Nitro
|
|
17
|
+
* enclave and signs the attestation directly.
|
|
18
|
+
*
|
|
19
|
+
* The response `responseObject` is the same `V3AttestationResponseObject`
|
|
20
|
+
* shape our gate returns, so it flows through the existing
|
|
21
|
+
* `encodeV3PaymentProof` path unchanged.
|
|
22
|
+
*
|
|
23
|
+
* Moved verbatim from `@provex/ui` (packages/ui/src/lib/buyerTeeAttestation.ts)
|
|
24
|
+
* with the base URL changed from a `@provex/ui` config import to an injected
|
|
25
|
+
* `attestationBaseUrl` argument so this package carries no `@provex/ui` dep.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Runtime shape of a buyerTee proof emitted by the PeerAuth extension.
|
|
30
|
+
* Narrow with {@link asBuyerTeeProof} before use.
|
|
31
|
+
*/
|
|
32
|
+
interface BuyerTeeProof {
|
|
33
|
+
proofType: 'buyerTee';
|
|
34
|
+
/** Session material already encrypted toward the enclave (opaque to us). */
|
|
35
|
+
encryptedSessionMaterial: string;
|
|
36
|
+
/** Platform-specific params, e.g. Revolut `{ index }`, Chase `{ index }`. */
|
|
37
|
+
params: unknown;
|
|
38
|
+
actionType?: string;
|
|
39
|
+
actionPlatform?: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Narrow an extension proof to a buyerTee proof, or null when it is the
|
|
43
|
+
* legacy Reclaim shape (or malformed).
|
|
44
|
+
*/
|
|
45
|
+
declare function asBuyerTeeProof(proof: unknown): BuyerTeeProof | null;
|
|
46
|
+
/** Intent details the enclave binds the attestation to. */
|
|
47
|
+
interface BuyerTeeIntent {
|
|
48
|
+
intentHash: Hex;
|
|
49
|
+
amount: string;
|
|
50
|
+
timestampMs: string;
|
|
51
|
+
paymentMethod: Hex;
|
|
52
|
+
fiatCurrency: Hex;
|
|
53
|
+
conversionRate: string;
|
|
54
|
+
payeeDetails: Hex;
|
|
55
|
+
timestampBufferMs?: string;
|
|
56
|
+
}
|
|
57
|
+
interface RequestBuyerTeeAttestationArgs {
|
|
58
|
+
/** Gate/attestation origin (was `gateForwarderBaseUrl` in @provex/ui). */
|
|
59
|
+
attestationBaseUrl: string;
|
|
60
|
+
/** Extension platform / bank key, e.g. `revolut`, `chase`. */
|
|
61
|
+
platform: string;
|
|
62
|
+
/** Action type, e.g. `transfer_revolut`, `transfer_zelle`. */
|
|
63
|
+
actionType: string;
|
|
64
|
+
/** Encrypted session material from the buyerTee capture. */
|
|
65
|
+
encryptedSessionMaterial: string;
|
|
66
|
+
/** Platform params from the capture (e.g. `{ index }`). */
|
|
67
|
+
params: unknown;
|
|
68
|
+
/** PulseChain UnifiedPaymentVerifier the gate re-signs the attestation for. */
|
|
69
|
+
verifyingContract: string;
|
|
70
|
+
intent: BuyerTeeIntent;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Verify a buyer payment via the gate. The gate proxies the encrypted capture
|
|
74
|
+
* to zkp2p's enclave, then re-signs the resulting attestation for PulseChain
|
|
75
|
+
* with our witness key — the enclave itself refuses to sign for 369.
|
|
76
|
+
*
|
|
77
|
+
* Throws with the gate's error text on a non-2xx response.
|
|
78
|
+
*/
|
|
79
|
+
declare function requestBuyerTeeAttestation(args: RequestBuyerTeeAttestationArgs): Promise<V3AttestationResponseObject>;
|
|
7
80
|
|
|
8
81
|
/**
|
|
9
82
|
* @fileoverview Pure proving derivations moved from @provex/ui
|
|
@@ -46,4 +119,83 @@ declare function computePartialFulfillment({ attestation, intentAmount, conversi
|
|
|
46
119
|
feeBps: bigint | null | undefined;
|
|
47
120
|
}): PartialFulfillment | null;
|
|
48
121
|
|
|
49
|
-
|
|
122
|
+
interface ManualTransactionSelect {
|
|
123
|
+
/**
|
|
124
|
+
* Resolver injected into useProving — the enclave adapter calls this when
|
|
125
|
+
* auto-match of the bank transaction fails (extensionEnclave.ts:189-190).
|
|
126
|
+
*/
|
|
127
|
+
selectTransaction: SelectTransaction;
|
|
128
|
+
/**
|
|
129
|
+
* Non-null while the adapter is awaiting a pick; drives the
|
|
130
|
+
* TransactionSelector rendered inside GenerateProofStep.
|
|
131
|
+
*/
|
|
132
|
+
candidates: CaptureCandidate[] | null;
|
|
133
|
+
/**
|
|
134
|
+
* Called by TransactionSelector with the chosen candidate's originalIndex.
|
|
135
|
+
* Resolves the pending promise and resets candidates to null.
|
|
136
|
+
*/
|
|
137
|
+
pick: (originalIndex: number) => void;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Bridge the framework-agnostic {@link SelectTransaction} resolver the enclave
|
|
141
|
+
* adapter expects (extensionEnclave.ts:189-190) to React state the
|
|
142
|
+
* GenerateProofStep TransactionSelector can render.
|
|
143
|
+
*
|
|
144
|
+
* The adapter awaits the promise returned by `selectTransaction`; the user's
|
|
145
|
+
* call to `pick` resolves it with the chosen `originalIndex`.
|
|
146
|
+
*
|
|
147
|
+
* `useRef` is justified here exclusively for holding the pending promise
|
|
148
|
+
* resolver across renders without triggering a re-render cycle — the single
|
|
149
|
+
* sanctioned use per the react-state-preferences memory.
|
|
150
|
+
*/
|
|
151
|
+
declare function useManualTransactionSelect(): ManualTransactionSelect;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* @fileoverview Pure builder that assembles a {@link CaptureRequest} from
|
|
155
|
+
* resolved order data.
|
|
156
|
+
*
|
|
157
|
+
* Hoisted verbatim from the intent-assembly block in SubmitStep.tsx:312-342
|
|
158
|
+
* so the mapping is unit-tested in isolation and reusable by the proving shell.
|
|
159
|
+
*
|
|
160
|
+
* Monetary values stay bigint in base units through the entire call stack;
|
|
161
|
+
* this is the single boundary where they are stringified for the attestor
|
|
162
|
+
* wire format.
|
|
163
|
+
*/
|
|
164
|
+
|
|
165
|
+
/** All resolved order fields required to build a {@link CaptureRequest}. */
|
|
166
|
+
interface BuildCaptureRequestInput {
|
|
167
|
+
/** On-chain intent hash. */
|
|
168
|
+
intentHash: Hex;
|
|
169
|
+
/** Chain the intent lives on. */
|
|
170
|
+
chainId: number;
|
|
171
|
+
/** Bank-level sub-provider, e.g. `'zelle-chase'`, or `null` for top-level providers. */
|
|
172
|
+
subProvider: SubProviderKey | null;
|
|
173
|
+
/** Provider key from the deposit. May itself be a sub-provider key (contains a dash). */
|
|
174
|
+
providerKey: ProviderKey | SubProviderKey;
|
|
175
|
+
/** Address of the UnifiedPaymentVerifier contract for this chain. */
|
|
176
|
+
verifyingContract: Hex;
|
|
177
|
+
/** payeeDetailsHash from the matched verifier record. */
|
|
178
|
+
payeeDetailsHash: Hex;
|
|
179
|
+
/** Settlement token for this intent (used by the adapter for amount conversion). */
|
|
180
|
+
token: TokenInfo;
|
|
181
|
+
/** Resolved intent fields, monetary values in bigint base units. */
|
|
182
|
+
intent: {
|
|
183
|
+
amount: bigint;
|
|
184
|
+
timestamp: bigint;
|
|
185
|
+
paymentMethod: Hex | undefined;
|
|
186
|
+
fiatCurrency: Hex;
|
|
187
|
+
conversionRate: bigint;
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Build the {@link CaptureRequest} from resolved order data.
|
|
192
|
+
*
|
|
193
|
+
* Pure hoist of the intent-assembly block in SubmitStep.tsx:312-342.
|
|
194
|
+
* No side effects, no I/O, no React. Safe to call in any environment.
|
|
195
|
+
*
|
|
196
|
+
* @param input - All resolved order fields needed to build the request.
|
|
197
|
+
* @returns A fully-formed {@link CaptureRequest} ready for a {@link CaptureAdapter}.
|
|
198
|
+
*/
|
|
199
|
+
declare function buildCaptureRequest(input: BuildCaptureRequestInput): CaptureRequest;
|
|
200
|
+
|
|
201
|
+
export { type BuildCaptureRequestInput, type BuyerTeeIntent, type BuyerTeeProof, CaptureCandidate, CaptureRequest, type ManualTransactionSelect, type PartialFulfillment, type RequestBuyerTeeAttestationArgs, SelectTransaction, asBuyerTeeProof, buildCaptureRequest, computePartialFulfillment, requestBuyerTeeAttestation, useManualTransactionSelect };
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,43 @@
|
|
|
1
|
-
export { useProving } from './chunk-
|
|
2
|
-
export { EnclaveCaptureUnavailable, ManualSelectionRequired, asBuyerTeeProof, createExtensionEnclaveAdapter, requestBuyerTeeAttestation } from './chunk-QLPNUQDA.js';
|
|
1
|
+
export { EnclaveCaptureUnavailable, ManualSelectionRequired, useProving } from './chunk-OSBIXUFA.js';
|
|
3
2
|
import { formatUnits } from '@provex/utils/units';
|
|
4
3
|
import { convertTokenInputToCurrency } from '@provex/utils/conversionRates';
|
|
5
4
|
import { calculateNetAmount, calculateFeeAmount } from '@provex/utils/fees';
|
|
5
|
+
import { useState, useRef, useCallback } from 'react';
|
|
6
|
+
import { getExtensionPlatform } from '@provex/utils/payment';
|
|
6
7
|
|
|
8
|
+
// src/buyerTeeAttestation.ts
|
|
9
|
+
function asBuyerTeeProof(proof) {
|
|
10
|
+
if (!proof || typeof proof !== "object") return null;
|
|
11
|
+
const candidate = proof;
|
|
12
|
+
if (candidate.proofType !== "buyerTee") return null;
|
|
13
|
+
if (typeof candidate.encryptedSessionMaterial !== "string") return null;
|
|
14
|
+
return candidate;
|
|
15
|
+
}
|
|
16
|
+
async function requestBuyerTeeAttestation(args) {
|
|
17
|
+
const url = `${args.attestationBaseUrl}/api/v0/attestation/buyer-verify/${encodeURIComponent(args.platform)}/${encodeURIComponent(args.actionType)}`;
|
|
18
|
+
const response = await fetch(url, {
|
|
19
|
+
method: "POST",
|
|
20
|
+
headers: { "content-type": "application/json" },
|
|
21
|
+
body: JSON.stringify({
|
|
22
|
+
encryptedSessionMaterial: args.encryptedSessionMaterial,
|
|
23
|
+
params: args.params,
|
|
24
|
+
verifyingContract: args.verifyingContract,
|
|
25
|
+
intent: args.intent
|
|
26
|
+
})
|
|
27
|
+
});
|
|
28
|
+
if (!response.ok) {
|
|
29
|
+
const detail = await response.text().catch(() => "");
|
|
30
|
+
throw new Error(
|
|
31
|
+
`Trusted-execution attestation failed (${response.status}): ${detail || response.statusText}`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
const json = await response.json();
|
|
35
|
+
const responseObject = json.responseObject ?? json;
|
|
36
|
+
if (!responseObject?.typedDataValue || !responseObject?.signature) {
|
|
37
|
+
throw new Error("Trusted-execution attestation response missing typedDataValue/signature");
|
|
38
|
+
}
|
|
39
|
+
return responseObject;
|
|
40
|
+
}
|
|
7
41
|
function computePartialFulfillment({
|
|
8
42
|
attestation,
|
|
9
43
|
intentAmount,
|
|
@@ -45,7 +79,45 @@ function computePartialFulfillment({
|
|
|
45
79
|
protocolFeeDisplay: protocolFee > 0n ? formatTokenDisplay(protocolFee) : null
|
|
46
80
|
};
|
|
47
81
|
}
|
|
82
|
+
function useManualTransactionSelect() {
|
|
83
|
+
const [candidates, setCandidates] = useState(null);
|
|
84
|
+
const resolveRef = useRef(null);
|
|
85
|
+
const selectTransaction = useCallback((next) => {
|
|
86
|
+
return new Promise((resolve) => {
|
|
87
|
+
resolveRef.current = resolve;
|
|
88
|
+
setCandidates(next);
|
|
89
|
+
});
|
|
90
|
+
}, []);
|
|
91
|
+
const pick = useCallback((originalIndex) => {
|
|
92
|
+
resolveRef.current?.(originalIndex);
|
|
93
|
+
resolveRef.current = null;
|
|
94
|
+
setCandidates(null);
|
|
95
|
+
}, []);
|
|
96
|
+
return { selectTransaction, candidates, pick };
|
|
97
|
+
}
|
|
98
|
+
function buildCaptureRequest(input) {
|
|
99
|
+
const parentProvider = input.providerKey.includes("-") ? input.providerKey.split("-")[0] : input.providerKey;
|
|
100
|
+
const platform = getExtensionPlatform(input.subProvider ?? input.providerKey);
|
|
101
|
+
return {
|
|
102
|
+
provider: input.providerKey,
|
|
103
|
+
platform,
|
|
104
|
+
actionType: `transfer_${parentProvider}`,
|
|
105
|
+
verifyingContract: input.verifyingContract,
|
|
106
|
+
chainId: input.chainId,
|
|
107
|
+
token: input.token,
|
|
108
|
+
intent: {
|
|
109
|
+
intentHash: input.intentHash,
|
|
110
|
+
amount: input.intent.amount.toString(),
|
|
111
|
+
timestampMs: (input.intent.timestamp * 1000n).toString(),
|
|
112
|
+
paymentMethod: input.intent.paymentMethod ?? "0x",
|
|
113
|
+
fiatCurrency: input.intent.fiatCurrency,
|
|
114
|
+
conversionRate: input.intent.conversionRate.toString(),
|
|
115
|
+
payeeDetails: input.payeeDetailsHash,
|
|
116
|
+
timestampBufferMs: "300000"
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
48
120
|
|
|
49
|
-
export { computePartialFulfillment };
|
|
121
|
+
export { asBuyerTeeProof, buildCaptureRequest, computePartialFulfillment, requestBuyerTeeAttestation, useManualTransactionSelect };
|
|
50
122
|
//# sourceMappingURL=index.js.map
|
|
51
123
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/derivations.ts"],"names":[],"mappings":";;;;;;AAwCO,SAAS,yBAAA,CAA0B;AAAA,EACxC,WAAA;AAAA,EACA,YAAA;AAAA,EACA,cAAA;AAAA,EACA,SAAA;AAAA,EACA;AACF,CAAA,EAM8B;AAC5B,EAAA,IAAI,CAAC,eAAe,CAAC,YAAA,IAAgB,CAAC,cAAA,IAAkB,CAAC,WAAW,OAAO,IAAA;AAC3E,EAAA,MAAM,aAAA,GAAgB,MAAA,CAAO,WAAA,CAAY,cAAA,CAAe,aAAa,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AAA,GAAI;AAAA,GAC3E;AACF","file":"index.js","sourcesContent":["/**\n * @fileoverview Pure proving derivations moved from @provex/ui\n * (packages/ui/src/components/UnifiedBuy/ProofPanel/submitStepDerivations.ts).\n *\n * Bigint throughout — see the `money-values-stay-bigint-until-display` rule.\n * The only string conversions happen at the formatter boundary (formatUnits),\n * which is the display layer.\n */\n\nimport type { V3AttestationResponseObject } from '@provex/utils'\nimport type { TokenInfo } from '@provex/utils/tokens'\nimport { formatUnits } from '@provex/utils/units'\nimport { convertTokenInputToCurrency } from '@provex/utils/conversionRates'\nimport { calculateFeeAmount, calculateNetAmount } from '@provex/utils/fees'\n\nexport interface PartialFulfillment {\n /** Gross USDC the gate authorized for release (typedData.releaseAmount). */\n grossReleased: bigint\n /** Net USDC the buyer actually receives (grossReleased − fee). */\n netToBuyer: bigint\n /** Protocol fee in USDC base units. 0n when no fee applies. */\n protocolFee: bigint\n /** Locked USDC returned to the maker (intent.amount − grossReleased). */\n returnedToMaker: bigint\n contractedFiatDisplay: string\n attestedFiatDisplay: string\n netToBuyerDisplay: string\n returnedToMakerDisplay: string\n /** null when protocolFee === 0n so the caller can skip rendering the row. */\n protocolFeeDisplay: string | null\n}\n\n/**\n * Partial-fulfilment breakdown derived from the verified attestation.\n *\n * Returns `null` when:\n * - attestation isn't present (nothing to compare)\n * - releaseAmount >= intent.amount (full settlement, no partial story)\n * - intent/tokenInfo missing (defensive)\n */\nexport function computePartialFulfillment({\n attestation,\n intentAmount,\n conversionRate,\n tokenInfo,\n feeBps,\n}: {\n attestation: V3AttestationResponseObject | null\n intentAmount: bigint | null | undefined\n conversionRate: bigint | null | undefined\n tokenInfo: TokenInfo | null\n feeBps: bigint | null | undefined\n}): PartialFulfillment | null {\n if (!attestation || !intentAmount || !conversionRate || !tokenInfo) return null\n const grossReleased = BigInt(attestation.typedDataValue.releaseAmount)\n if (grossReleased >= intentAmount) return null\n\n const returnedToMaker = intentAmount - grossReleased\n const effectiveFeeBps = feeBps ?? 0n\n const netToBuyer =\n effectiveFeeBps > 0n\n ? calculateNetAmount({ grossAmount: grossReleased, feeBps: effectiveFeeBps })\n : grossReleased\n const protocolFee =\n effectiveFeeBps > 0n\n ? calculateFeeAmount({ amount: grossReleased, feeBps: effectiveFeeBps })\n : 0n\n\n const contractedFiatRaw = convertTokenInputToCurrency({\n token: tokenInfo,\n amountOutInt: intentAmount,\n rate: conversionRate,\n })\n const attestedFiatRaw = convertTokenInputToCurrency({\n token: tokenInfo,\n amountOutInt: grossReleased,\n rate: conversionRate,\n })\n\n const formatTokenDisplay = (value: bigint): string =>\n formatUnits(value, {\n decimals: tokenInfo.decimals,\n truncateDecimals: 2,\n padDecimals: 2,\n })\n\n return {\n grossReleased,\n netToBuyer,\n protocolFee,\n returnedToMaker,\n contractedFiatDisplay: formatTokenDisplay(contractedFiatRaw),\n attestedFiatDisplay: formatTokenDisplay(attestedFiatRaw),\n netToBuyerDisplay: formatTokenDisplay(netToBuyer),\n returnedToMakerDisplay: formatTokenDisplay(returnedToMaker),\n protocolFeeDisplay: protocolFee > 0n ? formatTokenDisplay(protocolFee) : null,\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/buyerTeeAttestation.ts","../src/derivations.ts","../src/useManualTransactionSelect.ts","../src/buildCaptureRequest.ts"],"names":[],"mappings":";;;;;;;;AAyCO,SAAS,gBAAgB,KAAA,EAAsC;AACpE,EAAA,IAAI,CAAC,KAAA,IAAS,OAAO,KAAA,KAAU,UAAU,OAAO,IAAA;AAChD,EAAA,MAAM,SAAA,GAAY,KAAA;AAClB,EAAA,IAAI,SAAA,CAAU,SAAA,KAAc,UAAA,EAAY,OAAO,IAAA;AAC/C,EAAA,IAAI,OAAO,SAAA,CAAU,wBAAA,KAA6B,QAAA,EAAU,OAAO,IAAA;AACnE,EAAA,OAAO,SAAA;AACT;AAqCA,eAAsB,2BACpB,IAAA,EACsC;AACtC,EAAA,MAAM,GAAA,GAAM,CAAA,EAAG,IAAA,CAAK,kBAAkB,CAAA,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AAA,IACtC,mBAAmB,KAAA,CAAM,iBAAA;AAAA,IACzB,SAAS,KAAA,CAAM,OAAA;AAAA,IACf,OAAO,KAAA,CAAM,KAAA;AAAA,IACb,MAAA,EAAQ;AAAA,MACN,YAAY,KAAA,CAAM,UAAA;AAAA,MAClB,MAAA,EAAQ,KAAA,CAAM,MAAA,CAAO,MAAA,CAAO,QAAA,EAAS;AAAA,MACrC,WAAA,EAAA,CAAc,KAAA,CAAM,MAAA,CAAO,SAAA,GAAY,OAAO,QAAA,EAAS;AAAA,MACvD,aAAA,EAAe,KAAA,CAAM,MAAA,CAAO,aAAA,IAAkB,IAAA;AAAA,MAC9C,YAAA,EAAc,MAAM,MAAA,CAAO,YAAA;AAAA,MAC3B,cAAA,EAAgB,KAAA,CAAM,MAAA,CAAO,cAAA,CAAe,QAAA,EAAS;AAAA,MACrD,cAAc,KAAA,CAAM,gBAAA;AAAA,MACpB,iBAAA,EAAmB;AAAA;AACrB,GACF;AACF","file":"index.js","sourcesContent":["/**\n * @fileoverview Buyer trusted-execution attestation client.\n *\n * In PeerAuth extension 0.5.2+, capture produces a buyerTee proof —\n * `{ proofType: 'buyerTee', encryptedSessionMaterial, params }` — where the\n * bank session is already encrypted toward the enclave (cookies never reach\n * our page in plaintext). Instead of re-signing a Reclaim proof through our\n * gate, we hand that material to zkp2p's trusted-execution attestation\n * service, which verifies the payment inside an Amazon Web Services Nitro\n * enclave and signs the attestation directly.\n *\n * The response `responseObject` is the same `V3AttestationResponseObject`\n * shape our gate returns, so it flows through the existing\n * `encodeV3PaymentProof` path unchanged.\n *\n * Moved verbatim from `@provex/ui` (packages/ui/src/lib/buyerTeeAttestation.ts)\n * with the base URL changed from a `@provex/ui` config import to an injected\n * `attestationBaseUrl` argument so this package carries no `@provex/ui` dep.\n */\n\nimport type { Hex } from 'viem'\nimport type { V3AttestationResponseObject } from '@provex/utils'\n\n/**\n * Runtime shape of a buyerTee proof emitted by the PeerAuth extension.\n * Narrow with {@link asBuyerTeeProof} before use.\n */\nexport interface BuyerTeeProof {\n proofType: 'buyerTee'\n /** Session material already encrypted toward the enclave (opaque to us). */\n encryptedSessionMaterial: string\n /** Platform-specific params, e.g. Revolut `{ index }`, Chase `{ index }`. */\n params: unknown\n actionType?: string\n actionPlatform?: string\n}\n\n/**\n * Narrow an extension proof to a buyerTee proof, or null when it is the\n * legacy Reclaim shape (or malformed).\n */\nexport function asBuyerTeeProof(proof: unknown): BuyerTeeProof | null {\n if (!proof || typeof proof !== 'object') return null\n const candidate = proof as Record<string, unknown>\n if (candidate.proofType !== 'buyerTee') return null\n if (typeof candidate.encryptedSessionMaterial !== 'string') return null\n return candidate as unknown as BuyerTeeProof\n}\n\n/** Intent details the enclave binds the attestation to. */\nexport interface BuyerTeeIntent {\n intentHash: Hex\n amount: string\n timestampMs: string\n paymentMethod: Hex\n fiatCurrency: Hex\n conversionRate: string\n payeeDetails: Hex\n timestampBufferMs?: string\n}\n\nexport interface RequestBuyerTeeAttestationArgs {\n /** Gate/attestation origin (was `gateForwarderBaseUrl` in @provex/ui). */\n attestationBaseUrl: string\n /** Extension platform / bank key, e.g. `revolut`, `chase`. */\n platform: string\n /** Action type, e.g. `transfer_revolut`, `transfer_zelle`. */\n actionType: string\n /** Encrypted session material from the buyerTee capture. */\n encryptedSessionMaterial: string\n /** Platform params from the capture (e.g. `{ index }`). */\n params: unknown\n /** PulseChain UnifiedPaymentVerifier the gate re-signs the attestation for. */\n verifyingContract: string\n intent: BuyerTeeIntent\n}\n\n/**\n * Verify a buyer payment via the gate. The gate proxies the encrypted capture\n * to zkp2p's enclave, then re-signs the resulting attestation for PulseChain\n * with our witness key — the enclave itself refuses to sign for 369.\n *\n * Throws with the gate's error text on a non-2xx response.\n */\nexport async function requestBuyerTeeAttestation(\n args: RequestBuyerTeeAttestationArgs,\n): Promise<V3AttestationResponseObject> {\n const url = `${args.attestationBaseUrl}/api/v0/attestation/buyer-verify/${encodeURIComponent(args.platform)}/${encodeURIComponent(args.actionType)}`\n\n const response = await fetch(url, {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify({\n encryptedSessionMaterial: args.encryptedSessionMaterial,\n params: args.params,\n verifyingContract: args.verifyingContract,\n intent: args.intent,\n }),\n })\n\n if (!response.ok) {\n const detail = await response.text().catch(() => '')\n throw new Error(\n `Trusted-execution attestation failed (${response.status}): ${detail || response.statusText}`,\n )\n }\n\n const json = (await response.json()) as\n | { responseObject?: V3AttestationResponseObject }\n | V3AttestationResponseObject\n const responseObject =\n (json as { responseObject?: V3AttestationResponseObject }).responseObject ??\n (json as V3AttestationResponseObject)\n\n if (!responseObject?.typedDataValue || !responseObject?.signature) {\n throw new Error('Trusted-execution attestation response missing typedDataValue/signature')\n }\n return responseObject\n}\n","/**\n * @fileoverview Pure proving derivations moved from @provex/ui\n * (packages/ui/src/components/UnifiedBuy/ProofPanel/submitStepDerivations.ts).\n *\n * Bigint throughout — see the `money-values-stay-bigint-until-display` rule.\n * The only string conversions happen at the formatter boundary (formatUnits),\n * which is the display layer.\n */\n\nimport type { V3AttestationResponseObject } from '@provex/utils'\nimport type { TokenInfo } from '@provex/utils/tokens'\nimport { formatUnits } from '@provex/utils/units'\nimport { convertTokenInputToCurrency } from '@provex/utils/conversionRates'\nimport { calculateFeeAmount, calculateNetAmount } from '@provex/utils/fees'\n\nexport interface PartialFulfillment {\n /** Gross USDC the gate authorized for release (typedData.releaseAmount). */\n grossReleased: bigint\n /** Net USDC the buyer actually receives (grossReleased − fee). */\n netToBuyer: bigint\n /** Protocol fee in USDC base units. 0n when no fee applies. */\n protocolFee: bigint\n /** Locked USDC returned to the maker (intent.amount − grossReleased). */\n returnedToMaker: bigint\n contractedFiatDisplay: string\n attestedFiatDisplay: string\n netToBuyerDisplay: string\n returnedToMakerDisplay: string\n /** null when protocolFee === 0n so the caller can skip rendering the row. */\n protocolFeeDisplay: string | null\n}\n\n/**\n * Partial-fulfilment breakdown derived from the verified attestation.\n *\n * Returns `null` when:\n * - attestation isn't present (nothing to compare)\n * - releaseAmount >= intent.amount (full settlement, no partial story)\n * - intent/tokenInfo missing (defensive)\n */\nexport function computePartialFulfillment({\n attestation,\n intentAmount,\n conversionRate,\n tokenInfo,\n feeBps,\n}: {\n attestation: V3AttestationResponseObject | null\n intentAmount: bigint | null | undefined\n conversionRate: bigint | null | undefined\n tokenInfo: TokenInfo | null\n feeBps: bigint | null | undefined\n}): PartialFulfillment | null {\n if (!attestation || !intentAmount || !conversionRate || !tokenInfo) return null\n const grossReleased = BigInt(attestation.typedDataValue.releaseAmount)\n if (grossReleased >= intentAmount) return null\n\n const returnedToMaker = intentAmount - grossReleased\n const effectiveFeeBps = feeBps ?? 0n\n const netToBuyer =\n effectiveFeeBps > 0n\n ? calculateNetAmount({ grossAmount: grossReleased, feeBps: effectiveFeeBps })\n : grossReleased\n const protocolFee =\n effectiveFeeBps > 0n\n ? calculateFeeAmount({ amount: grossReleased, feeBps: effectiveFeeBps })\n : 0n\n\n const contractedFiatRaw = convertTokenInputToCurrency({\n token: tokenInfo,\n amountOutInt: intentAmount,\n rate: conversionRate,\n })\n const attestedFiatRaw = convertTokenInputToCurrency({\n token: tokenInfo,\n amountOutInt: grossReleased,\n rate: conversionRate,\n })\n\n const formatTokenDisplay = (value: bigint): string =>\n formatUnits(value, {\n decimals: tokenInfo.decimals,\n truncateDecimals: 2,\n padDecimals: 2,\n })\n\n return {\n grossReleased,\n netToBuyer,\n protocolFee,\n returnedToMaker,\n contractedFiatDisplay: formatTokenDisplay(contractedFiatRaw),\n attestedFiatDisplay: formatTokenDisplay(attestedFiatRaw),\n netToBuyerDisplay: formatTokenDisplay(netToBuyer),\n returnedToMakerDisplay: formatTokenDisplay(returnedToMaker),\n protocolFeeDisplay: protocolFee > 0n ? formatTokenDisplay(protocolFee) : null,\n }\n}\n","import { useCallback, useRef, useState } from 'react'\nimport type { CaptureCandidate, SelectTransaction } from './types'\n\nexport interface ManualTransactionSelect {\n /**\n * Resolver injected into useProving — the enclave adapter calls this when\n * auto-match of the bank transaction fails (extensionEnclave.ts:189-190).\n */\n selectTransaction: SelectTransaction\n /**\n * Non-null while the adapter is awaiting a pick; drives the\n * TransactionSelector rendered inside GenerateProofStep.\n */\n candidates: CaptureCandidate[] | null\n /**\n * Called by TransactionSelector with the chosen candidate's originalIndex.\n * Resolves the pending promise and resets candidates to null.\n */\n pick: (originalIndex: number) => void\n}\n\n/**\n * Bridge the framework-agnostic {@link SelectTransaction} resolver the enclave\n * adapter expects (extensionEnclave.ts:189-190) to React state the\n * GenerateProofStep TransactionSelector can render.\n *\n * The adapter awaits the promise returned by `selectTransaction`; the user's\n * call to `pick` resolves it with the chosen `originalIndex`.\n *\n * `useRef` is justified here exclusively for holding the pending promise\n * resolver across renders without triggering a re-render cycle — the single\n * sanctioned use per the react-state-preferences memory.\n */\nexport function useManualTransactionSelect(): ManualTransactionSelect {\n const [candidates, setCandidates] = useState<CaptureCandidate[] | null>(null)\n const resolveRef = useRef<((originalIndex: number) => void) | null>(null)\n\n const selectTransaction = useCallback<SelectTransaction>((next) => {\n return new Promise<number>((resolve) => {\n resolveRef.current = resolve\n setCandidates(next)\n })\n }, [])\n\n const pick = useCallback((originalIndex: number) => {\n resolveRef.current?.(originalIndex)\n resolveRef.current = null\n setCandidates(null)\n }, [])\n\n return { selectTransaction, candidates, pick }\n}\n","/**\n * @fileoverview Pure builder that assembles a {@link CaptureRequest} from\n * resolved order data.\n *\n * Hoisted verbatim from the intent-assembly block in SubmitStep.tsx:312-342\n * so the mapping is unit-tested in isolation and reusable by the proving shell.\n *\n * Monetary values stay bigint in base units through the entire call stack;\n * this is the single boundary where they are stringified for the attestor\n * wire format.\n */\n\nimport type { Hex } from 'viem'\nimport type { CaptureRequest } from './types'\nimport { getExtensionPlatform } from '@provex/utils/payment'\nimport type { ProviderKey, SubProviderKey } from '@provex/utils/payment'\nimport type { TokenInfo } from '@provex/utils/tokens'\n\n/** All resolved order fields required to build a {@link CaptureRequest}. */\nexport interface BuildCaptureRequestInput {\n /** On-chain intent hash. */\n intentHash: Hex\n /** Chain the intent lives on. */\n chainId: number\n /** Bank-level sub-provider, e.g. `'zelle-chase'`, or `null` for top-level providers. */\n subProvider: SubProviderKey | null\n /** Provider key from the deposit. May itself be a sub-provider key (contains a dash). */\n providerKey: ProviderKey | SubProviderKey\n /** Address of the UnifiedPaymentVerifier contract for this chain. */\n verifyingContract: Hex\n /** payeeDetailsHash from the matched verifier record. */\n payeeDetailsHash: Hex\n /** Settlement token for this intent (used by the adapter for amount conversion). */\n token: TokenInfo\n /** Resolved intent fields, monetary values in bigint base units. */\n intent: {\n amount: bigint\n timestamp: bigint\n paymentMethod: Hex | undefined\n fiatCurrency: Hex\n conversionRate: bigint\n }\n}\n\n/**\n * Build the {@link CaptureRequest} from resolved order data.\n *\n * Pure hoist of the intent-assembly block in SubmitStep.tsx:312-342.\n * No side effects, no I/O, no React. Safe to call in any environment.\n *\n * @param input - All resolved order fields needed to build the request.\n * @returns A fully-formed {@link CaptureRequest} ready for a {@link CaptureAdapter}.\n */\nexport function buildCaptureRequest(input: BuildCaptureRequestInput): CaptureRequest {\n const parentProvider = input.providerKey.includes('-')\n ? input.providerKey.split('-')[0]\n : input.providerKey\n\n const platform = getExtensionPlatform(input.subProvider ?? input.providerKey)\n\n return {\n provider: input.providerKey,\n platform,\n actionType: `transfer_${parentProvider}`,\n verifyingContract: input.verifyingContract,\n chainId: input.chainId,\n token: input.token,\n intent: {\n intentHash: input.intentHash,\n amount: input.intent.amount.toString(),\n timestampMs: (input.intent.timestamp * 1000n).toString(),\n paymentMethod: input.intent.paymentMethod ?? ('0x' as Hex),\n fiatCurrency: input.intent.fiatCurrency,\n conversionRate: input.intent.conversionRate.toString(),\n payeeDetails: input.payeeDetailsHash,\n timestampBufferMs: '300000',\n },\n }\n}\n"]}
|
|
@@ -120,6 +120,11 @@ type ProvingState = {
|
|
|
120
120
|
/** true ⇒ failure occurred during/after on-chain submission. */
|
|
121
121
|
isSubmissionError: boolean;
|
|
122
122
|
attestation?: VerifiedAttestation;
|
|
123
|
+
/** Typed reason, set for cases the consumer must branch on. Currently
|
|
124
|
+
* 'enclave-unavailable' (non-migrated provider → caller falls back to
|
|
125
|
+
* Reclaim) and 'manual-selection-required' (auto-match failed, no
|
|
126
|
+
* resolver supplied). Absent for ordinary verification/submission errors. */
|
|
127
|
+
code?: 'enclave-unavailable' | 'manual-selection-required';
|
|
123
128
|
};
|
|
124
129
|
/**
|
|
125
130
|
* Thrown by a capture adapter when the provider returned no buyerTee capture
|
|
@@ -141,4 +146,96 @@ declare class ManualSelectionRequired extends Error {
|
|
|
141
146
|
constructor(candidates: CaptureCandidate[]);
|
|
142
147
|
}
|
|
143
148
|
|
|
144
|
-
|
|
149
|
+
/**
|
|
150
|
+
* @fileoverview useProving — headless orchestrator for the enclave proving
|
|
151
|
+
* pipeline. Replicates the live AuthenticateStep/GenerateProofStep/SubmitStep
|
|
152
|
+
* state machine (ProofPanel) with no presentation. Renders nothing; returns
|
|
153
|
+
* state + actions for a UI (UnifiedBuy ProofPanel or a wallet) to bind to.
|
|
154
|
+
*
|
|
155
|
+
* Owns: the ProvingState machine, the nullifier double-spend check
|
|
156
|
+
* (SubmitStep.tsx:419-426), the attest→fulfil sequencing, retry routing
|
|
157
|
+
* (SubmitStep.tsx:931-955), and the minimum-visible-state timings
|
|
158
|
+
* (SubmitStep.tsx:404-417). Delegates capture to the injected CaptureAdapter,
|
|
159
|
+
* the on-chain write (+ receipt + indexer sync) to ProveXClient.fulfillIntent.
|
|
160
|
+
*/
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Minimal context object that buildWritableMethod passes to the per-call hooks.
|
|
164
|
+
* Kept structural so @provex/proving does not depend on @valve-tech/wallet-adapter.
|
|
165
|
+
* Only `hash` is consumed by this hook — the rest is opaque context.
|
|
166
|
+
*/
|
|
167
|
+
interface TxCallbackContext {
|
|
168
|
+
chainId: number;
|
|
169
|
+
request: unknown;
|
|
170
|
+
}
|
|
171
|
+
/** Structural params for the fulfillIntent call. Mirrors FulfillIntentParams +
|
|
172
|
+
* WriteHookParams from @provex/react but declared here to keep @provex/proving
|
|
173
|
+
* from depending on the React package's built dist (which the test environment
|
|
174
|
+
* doesn't require). The real ProveXClient.fulfillIntent satisfies this shape.
|
|
175
|
+
*
|
|
176
|
+
* IMPORTANT: onAwaitingSignature and onTransactionHash match the exact call
|
|
177
|
+
* shapes in buildWritableMethod (ProveXClient.ts ~890, ~903):
|
|
178
|
+
* params.onAwaitingSignature?.(ctx) → (info: TxCallbackContext) => void
|
|
179
|
+
* params.onTransactionHash?.({ ...ctx, hash }) → (info: TxCallbackContext & { hash: Hex }) => void
|
|
180
|
+
*/
|
|
181
|
+
interface FulfillParams {
|
|
182
|
+
intentHash: Hex;
|
|
183
|
+
attestation: V3AttestationResponseObject;
|
|
184
|
+
verificationData: Hex;
|
|
185
|
+
postIntentHookData?: Hex;
|
|
186
|
+
onAwaitingSignature?: (info: TxCallbackContext) => void;
|
|
187
|
+
onTransactionHash?: (info: TxCallbackContext & {
|
|
188
|
+
hash: Hex;
|
|
189
|
+
}) => void;
|
|
190
|
+
}
|
|
191
|
+
/** The structural slice of ProveXClient the orchestrator depends on. Keeping
|
|
192
|
+
* it structural lets tests pass a light fake and avoids importing the class. */
|
|
193
|
+
interface ProvingClient {
|
|
194
|
+
/**
|
|
195
|
+
* The chain this rail operates on. Must equal request.chainId — useProving
|
|
196
|
+
* refuses to check the nullifier or submit on any other chain. A nullifier is
|
|
197
|
+
* only meaningful on its intended chain; checking it on (or submitting it to)
|
|
198
|
+
* a different chain is a cross-chain double-spend / replay vector.
|
|
199
|
+
*/
|
|
200
|
+
readonly chainId: number;
|
|
201
|
+
fulfillIntent: (params: FulfillParams) => Promise<{
|
|
202
|
+
hash: Hex;
|
|
203
|
+
receipt: unknown;
|
|
204
|
+
}>;
|
|
205
|
+
checkNullifierUsed: (params: {
|
|
206
|
+
paymentMethodId: Hex;
|
|
207
|
+
nullifier: Hex;
|
|
208
|
+
}) => Promise<boolean | null>;
|
|
209
|
+
}
|
|
210
|
+
interface UseProvingOptions {
|
|
211
|
+
client: ProvingClient;
|
|
212
|
+
captureAdapter: CaptureAdapter;
|
|
213
|
+
request: CaptureRequest;
|
|
214
|
+
/** Payment method id for the nullifier registry lookup. */
|
|
215
|
+
paymentMethodId: Hex;
|
|
216
|
+
/** Manual-select resolver forwarded to the adapter. */
|
|
217
|
+
selectTransaction?: SelectTransaction;
|
|
218
|
+
/**
|
|
219
|
+
* Forwarded to ProveXClient.fulfillIntent for the consumer's tx-flight strip.
|
|
220
|
+
* Receives the raw TxContext — the hook does not inspect the argument.
|
|
221
|
+
*/
|
|
222
|
+
onAwaitingSignature?: () => void;
|
|
223
|
+
/** Receives the raw tx hash extracted from the TxContext+hash payload. */
|
|
224
|
+
onTransactionHash?: (hash: Hex) => void;
|
|
225
|
+
/** Called once when the flow reaches `complete`. */
|
|
226
|
+
onComplete?: (attestation: V3AttestationResponseObject) => void;
|
|
227
|
+
}
|
|
228
|
+
interface UseProvingReturn {
|
|
229
|
+
state: ProvingState;
|
|
230
|
+
/** Phase 1+2: authenticate, capture, attest, nullifier-check → readyToFulfill. */
|
|
231
|
+
authenticate: () => Promise<void>;
|
|
232
|
+
/** Phase 3: submit fulfillIntent → confirm → sync → complete. */
|
|
233
|
+
fulfill: () => Promise<void>;
|
|
234
|
+
/** Re-run attestation after a pre-fulfilment error. */
|
|
235
|
+
retryVerification: () => Promise<void>;
|
|
236
|
+
/** Re-run submission after a post-fulfilment error. */
|
|
237
|
+
retrySubmission: () => Promise<void>;
|
|
238
|
+
}
|
|
239
|
+
declare function useProving(options: UseProvingOptions): UseProvingReturn;
|
|
240
|
+
|
|
241
|
+
export { type CaptureCandidate as C, EnclaveCaptureUnavailable as E, ManualSelectionRequired as M, type ProvingIntent as P, type SelectTransaction as S, type UseProvingOptions as U, type VerifiedAttestation as V, type CaptureRequest as a, type CaptureHandle as b, type CaptureAdapter as c, type ProvingRequest as d, type ProvingState as e, type ProvingClient as f, type UseProvingReturn as g, useProving as u };
|