@provex/proving 1.8.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 +6 -0
- package/dist/adapters/extensionEnclave.cjs +160 -0
- package/dist/adapters/extensionEnclave.cjs.map +1 -0
- package/dist/adapters/extensionEnclave.d.cts +5 -0
- package/dist/adapters/extensionEnclave.d.ts +5 -0
- package/dist/adapters/extensionEnclave.js +3 -0
- package/dist/adapters/extensionEnclave.js.map +1 -0
- package/dist/chunk-LFDS3XGK.js +123 -0
- package/dist/chunk-LFDS3XGK.js.map +1 -0
- package/dist/chunk-QLPNUQDA.js +157 -0
- package/dist/chunk-QLPNUQDA.js.map +1 -0
- package/dist/extensionEnclave-BjxXsuaj.d.cts +119 -0
- package/dist/extensionEnclave-DLCjCWxT.d.ts +119 -0
- package/dist/index.cjs +321 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +49 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.js +51 -0
- package/dist/index.js.map +1 -0
- package/dist/types-ByiBb7AN.d.cts +144 -0
- package/dist/types-ByiBb7AN.d.ts +144 -0
- package/dist/useProving.cjs +125 -0
- package/dist/useProving.cjs.map +1 -0
- package/dist/useProving.d.cts +91 -0
- package/dist/useProving.d.ts +91 -0
- package/dist/useProving.js +3 -0
- package/dist/useProving.js.map +1 -0
- package/package.json +66 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Hex } from 'viem';
|
|
2
|
+
import { V3AttestationResponseObject } from '@provex/utils';
|
|
3
|
+
import { c as CaptureAdapter, a as CaptureRequest, S as SelectTransaction, e as ProvingState } from './types-ByiBb7AN.cjs';
|
|
4
|
+
import '@provex/utils/tokens';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @fileoverview useProving — headless orchestrator for the enclave proving
|
|
8
|
+
* pipeline. Replicates the live AuthenticateStep/GenerateProofStep/SubmitStep
|
|
9
|
+
* state machine (ProofPanel) with no presentation. Renders nothing; returns
|
|
10
|
+
* state + actions for a UI (UnifiedBuy ProofPanel or a wallet) to bind to.
|
|
11
|
+
*
|
|
12
|
+
* Owns: the ProvingState machine, the nullifier double-spend check
|
|
13
|
+
* (SubmitStep.tsx:419-426), the attest→fulfil sequencing, retry routing
|
|
14
|
+
* (SubmitStep.tsx:931-955), and the minimum-visible-state timings
|
|
15
|
+
* (SubmitStep.tsx:404-417). Delegates capture to the injected CaptureAdapter,
|
|
16
|
+
* the on-chain write (+ receipt + indexer sync) to ProveXClient.fulfillIntent.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Minimal context object that buildWritableMethod passes to the per-call hooks.
|
|
21
|
+
* Kept structural so @provex/proving does not depend on @valve-tech/wallet-adapter.
|
|
22
|
+
* Only `hash` is consumed by this hook — the rest is opaque context.
|
|
23
|
+
*/
|
|
24
|
+
interface TxCallbackContext {
|
|
25
|
+
chainId: number;
|
|
26
|
+
request: unknown;
|
|
27
|
+
}
|
|
28
|
+
/** Structural params for the fulfillIntent call. Mirrors FulfillIntentParams +
|
|
29
|
+
* WriteHookParams from @provex/react but declared here to keep @provex/proving
|
|
30
|
+
* from depending on the React package's built dist (which the test environment
|
|
31
|
+
* doesn't require). The real ProveXClient.fulfillIntent satisfies this shape.
|
|
32
|
+
*
|
|
33
|
+
* IMPORTANT: onAwaitingSignature and onTransactionHash match the exact call
|
|
34
|
+
* shapes in buildWritableMethod (ProveXClient.ts ~890, ~903):
|
|
35
|
+
* params.onAwaitingSignature?.(ctx) → (info: TxCallbackContext) => void
|
|
36
|
+
* params.onTransactionHash?.({ ...ctx, hash }) → (info: TxCallbackContext & { hash: Hex }) => void
|
|
37
|
+
*/
|
|
38
|
+
interface FulfillParams {
|
|
39
|
+
intentHash: Hex;
|
|
40
|
+
attestation: V3AttestationResponseObject;
|
|
41
|
+
verificationData: Hex;
|
|
42
|
+
postIntentHookData?: Hex;
|
|
43
|
+
onAwaitingSignature?: (info: TxCallbackContext) => void;
|
|
44
|
+
onTransactionHash?: (info: TxCallbackContext & {
|
|
45
|
+
hash: Hex;
|
|
46
|
+
}) => void;
|
|
47
|
+
}
|
|
48
|
+
/** The structural slice of ProveXClient the orchestrator depends on. Keeping
|
|
49
|
+
* it structural lets tests pass a light fake and avoids importing the class. */
|
|
50
|
+
interface ProvingClient {
|
|
51
|
+
fulfillIntent: (params: FulfillParams) => Promise<{
|
|
52
|
+
hash: Hex;
|
|
53
|
+
receipt: unknown;
|
|
54
|
+
}>;
|
|
55
|
+
checkNullifierUsed: (params: {
|
|
56
|
+
paymentMethodId: Hex;
|
|
57
|
+
nullifier: Hex;
|
|
58
|
+
}) => Promise<boolean | null>;
|
|
59
|
+
}
|
|
60
|
+
interface UseProvingOptions {
|
|
61
|
+
client: ProvingClient;
|
|
62
|
+
captureAdapter: CaptureAdapter;
|
|
63
|
+
request: CaptureRequest;
|
|
64
|
+
/** Payment method id for the nullifier registry lookup. */
|
|
65
|
+
paymentMethodId: Hex;
|
|
66
|
+
/** Manual-select resolver forwarded to the adapter. */
|
|
67
|
+
selectTransaction?: SelectTransaction;
|
|
68
|
+
/**
|
|
69
|
+
* Forwarded to ProveXClient.fulfillIntent for the consumer's tx-flight strip.
|
|
70
|
+
* Receives the raw TxContext — the hook does not inspect the argument.
|
|
71
|
+
*/
|
|
72
|
+
onAwaitingSignature?: () => void;
|
|
73
|
+
/** Receives the raw tx hash extracted from the TxContext+hash payload. */
|
|
74
|
+
onTransactionHash?: (hash: Hex) => void;
|
|
75
|
+
/** Called once when the flow reaches `complete`. */
|
|
76
|
+
onComplete?: (attestation: V3AttestationResponseObject) => void;
|
|
77
|
+
}
|
|
78
|
+
interface UseProvingReturn {
|
|
79
|
+
state: ProvingState;
|
|
80
|
+
/** Phase 1+2: authenticate, capture, attest, nullifier-check → readyToFulfill. */
|
|
81
|
+
authenticate: () => Promise<void>;
|
|
82
|
+
/** Phase 3: submit fulfillIntent → confirm → sync → complete. */
|
|
83
|
+
fulfill: () => Promise<void>;
|
|
84
|
+
/** Re-run attestation after a pre-fulfilment error. */
|
|
85
|
+
retryVerification: () => Promise<void>;
|
|
86
|
+
/** Re-run submission after a post-fulfilment error. */
|
|
87
|
+
retrySubmission: () => Promise<void>;
|
|
88
|
+
}
|
|
89
|
+
declare function useProving(options: UseProvingOptions): UseProvingReturn;
|
|
90
|
+
|
|
91
|
+
export { type ProvingClient, type UseProvingOptions, type UseProvingReturn, useProving };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Hex } from 'viem';
|
|
2
|
+
import { V3AttestationResponseObject } from '@provex/utils';
|
|
3
|
+
import { c as CaptureAdapter, a as CaptureRequest, S as SelectTransaction, e as ProvingState } from './types-ByiBb7AN.js';
|
|
4
|
+
import '@provex/utils/tokens';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @fileoverview useProving — headless orchestrator for the enclave proving
|
|
8
|
+
* pipeline. Replicates the live AuthenticateStep/GenerateProofStep/SubmitStep
|
|
9
|
+
* state machine (ProofPanel) with no presentation. Renders nothing; returns
|
|
10
|
+
* state + actions for a UI (UnifiedBuy ProofPanel or a wallet) to bind to.
|
|
11
|
+
*
|
|
12
|
+
* Owns: the ProvingState machine, the nullifier double-spend check
|
|
13
|
+
* (SubmitStep.tsx:419-426), the attest→fulfil sequencing, retry routing
|
|
14
|
+
* (SubmitStep.tsx:931-955), and the minimum-visible-state timings
|
|
15
|
+
* (SubmitStep.tsx:404-417). Delegates capture to the injected CaptureAdapter,
|
|
16
|
+
* the on-chain write (+ receipt + indexer sync) to ProveXClient.fulfillIntent.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Minimal context object that buildWritableMethod passes to the per-call hooks.
|
|
21
|
+
* Kept structural so @provex/proving does not depend on @valve-tech/wallet-adapter.
|
|
22
|
+
* Only `hash` is consumed by this hook — the rest is opaque context.
|
|
23
|
+
*/
|
|
24
|
+
interface TxCallbackContext {
|
|
25
|
+
chainId: number;
|
|
26
|
+
request: unknown;
|
|
27
|
+
}
|
|
28
|
+
/** Structural params for the fulfillIntent call. Mirrors FulfillIntentParams +
|
|
29
|
+
* WriteHookParams from @provex/react but declared here to keep @provex/proving
|
|
30
|
+
* from depending on the React package's built dist (which the test environment
|
|
31
|
+
* doesn't require). The real ProveXClient.fulfillIntent satisfies this shape.
|
|
32
|
+
*
|
|
33
|
+
* IMPORTANT: onAwaitingSignature and onTransactionHash match the exact call
|
|
34
|
+
* shapes in buildWritableMethod (ProveXClient.ts ~890, ~903):
|
|
35
|
+
* params.onAwaitingSignature?.(ctx) → (info: TxCallbackContext) => void
|
|
36
|
+
* params.onTransactionHash?.({ ...ctx, hash }) → (info: TxCallbackContext & { hash: Hex }) => void
|
|
37
|
+
*/
|
|
38
|
+
interface FulfillParams {
|
|
39
|
+
intentHash: Hex;
|
|
40
|
+
attestation: V3AttestationResponseObject;
|
|
41
|
+
verificationData: Hex;
|
|
42
|
+
postIntentHookData?: Hex;
|
|
43
|
+
onAwaitingSignature?: (info: TxCallbackContext) => void;
|
|
44
|
+
onTransactionHash?: (info: TxCallbackContext & {
|
|
45
|
+
hash: Hex;
|
|
46
|
+
}) => void;
|
|
47
|
+
}
|
|
48
|
+
/** The structural slice of ProveXClient the orchestrator depends on. Keeping
|
|
49
|
+
* it structural lets tests pass a light fake and avoids importing the class. */
|
|
50
|
+
interface ProvingClient {
|
|
51
|
+
fulfillIntent: (params: FulfillParams) => Promise<{
|
|
52
|
+
hash: Hex;
|
|
53
|
+
receipt: unknown;
|
|
54
|
+
}>;
|
|
55
|
+
checkNullifierUsed: (params: {
|
|
56
|
+
paymentMethodId: Hex;
|
|
57
|
+
nullifier: Hex;
|
|
58
|
+
}) => Promise<boolean | null>;
|
|
59
|
+
}
|
|
60
|
+
interface UseProvingOptions {
|
|
61
|
+
client: ProvingClient;
|
|
62
|
+
captureAdapter: CaptureAdapter;
|
|
63
|
+
request: CaptureRequest;
|
|
64
|
+
/** Payment method id for the nullifier registry lookup. */
|
|
65
|
+
paymentMethodId: Hex;
|
|
66
|
+
/** Manual-select resolver forwarded to the adapter. */
|
|
67
|
+
selectTransaction?: SelectTransaction;
|
|
68
|
+
/**
|
|
69
|
+
* Forwarded to ProveXClient.fulfillIntent for the consumer's tx-flight strip.
|
|
70
|
+
* Receives the raw TxContext — the hook does not inspect the argument.
|
|
71
|
+
*/
|
|
72
|
+
onAwaitingSignature?: () => void;
|
|
73
|
+
/** Receives the raw tx hash extracted from the TxContext+hash payload. */
|
|
74
|
+
onTransactionHash?: (hash: Hex) => void;
|
|
75
|
+
/** Called once when the flow reaches `complete`. */
|
|
76
|
+
onComplete?: (attestation: V3AttestationResponseObject) => void;
|
|
77
|
+
}
|
|
78
|
+
interface UseProvingReturn {
|
|
79
|
+
state: ProvingState;
|
|
80
|
+
/** Phase 1+2: authenticate, capture, attest, nullifier-check → readyToFulfill. */
|
|
81
|
+
authenticate: () => Promise<void>;
|
|
82
|
+
/** Phase 3: submit fulfillIntent → confirm → sync → complete. */
|
|
83
|
+
fulfill: () => Promise<void>;
|
|
84
|
+
/** Re-run attestation after a pre-fulfilment error. */
|
|
85
|
+
retryVerification: () => Promise<void>;
|
|
86
|
+
/** Re-run submission after a post-fulfilment error. */
|
|
87
|
+
retrySubmission: () => Promise<void>;
|
|
88
|
+
}
|
|
89
|
+
declare function useProving(options: UseProvingOptions): UseProvingReturn;
|
|
90
|
+
|
|
91
|
+
export { type ProvingClient, type UseProvingOptions, type UseProvingReturn, useProving };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"useProving.js"}
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@provex/proving",
|
|
3
|
+
"version": "1.8.0",
|
|
4
|
+
"description": "Headless enclave proving orchestrator for the Provex buy flow",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/provex-tech/monorepo.git",
|
|
9
|
+
"directory": "packages/proving"
|
|
10
|
+
},
|
|
11
|
+
"main": "./dist/index.cjs",
|
|
12
|
+
"module": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js",
|
|
18
|
+
"require": "./dist/index.cjs"
|
|
19
|
+
},
|
|
20
|
+
"./useProving": {
|
|
21
|
+
"types": "./dist/useProving.d.ts",
|
|
22
|
+
"import": "./dist/useProving.js",
|
|
23
|
+
"require": "./dist/useProving.cjs"
|
|
24
|
+
},
|
|
25
|
+
"./adapters/extensionEnclave": {
|
|
26
|
+
"types": "./dist/adapters/extensionEnclave.d.ts",
|
|
27
|
+
"import": "./dist/adapters/extensionEnclave.js",
|
|
28
|
+
"require": "./dist/adapters/extensionEnclave.cjs"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"files": [
|
|
36
|
+
"dist",
|
|
37
|
+
"README.md"
|
|
38
|
+
],
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsup",
|
|
41
|
+
"dev": "tsup --watch",
|
|
42
|
+
"lint": "tsc --noEmit",
|
|
43
|
+
"test": "vitest run",
|
|
44
|
+
"test:watch": "vitest"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@provex/react": "1.8.0",
|
|
48
|
+
"@provex/utils": "1.8.0"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
52
|
+
"viem": "^2.0.0"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@testing-library/dom": "^10.4.0",
|
|
56
|
+
"@testing-library/react": "^16.2.0",
|
|
57
|
+
"@types/react": "^18.3.3",
|
|
58
|
+
"jsdom": "^26.0.0",
|
|
59
|
+
"react": "^18.2.0",
|
|
60
|
+
"react-dom": "^18.2.0",
|
|
61
|
+
"tsup": "^8.0.0",
|
|
62
|
+
"typescript": "^5.9.2",
|
|
63
|
+
"viem": "^2.38.0",
|
|
64
|
+
"vitest": "^2.1.8"
|
|
65
|
+
}
|
|
66
|
+
}
|