@zkproofport-app/sdk 0.4.1 → 0.4.2

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 CHANGED
@@ -692,7 +692,8 @@ When you are done, `sdk.disconnect()` closes any open socket.
692
692
  | `publicInputs` | `string[]` | `'completed'` | The circuit's public inputs **in circuit order**. This is the part that carries meaning — what each index holds is in [Public Input Layout Constants](#public-input-layout-constants). |
693
693
  | `verifierAddress` | `string` | `'completed'` | Address of the Solidity verifier contract that can check this exact proof. It comes from the mobile app — forward it, do not hardcode one. |
694
694
  | `chainId` | `number` | `'completed'` | The chain that `verifierAddress` lives on. Same rule: forward it. |
695
- | `error` | `string` | failures | Human-readable reason from the mobile app or the relay. |
695
+ | `error` | `string` | `'error'`, `'failed'`, `'expired'` | Human-readable reason from the mobile app or the relay. |
696
+ | `errorCode` | `string` | some `'error'` results | The app's error code, `E` + four digits (e.g. `'E2007'`). Absent when the app did not send one. |
696
697
  | `deepLink` | `string` | polling path only | The deep link the request was created with. |
697
698
  | `createdAt`, `updatedAt` | `string` | polling path only | ISO timestamps of creation and last update. |
698
699
 
@@ -703,37 +704,40 @@ The last three come from the relay's polling endpoint. `waitForProof()` normally
703
704
  | `status` | Terminal | What happened | What you do |
704
705
  |----------|----------|---------------|-------------|
705
706
  | `'pending'` | no | The request exists; no proof yet | Keep waiting — `waitForProof()` does that for you |
707
+ | `'generating'` | no | The app is producing the proof | Keep waiting |
706
708
  | `'completed'` | yes | A proof came back | `proof`, `publicInputs`, `verifierAddress` and `chainId` are set. Verify it (Step 7) before trusting anything in it |
707
- | `'error'` | yes | The app could not produce a proof — no attestation on that address, sign-in refused, generation failed | Read `error`, show it, let the user start over |
708
- | `'failed'` | yes | Same meaning and same handling as `'error'` | Handle the pair; the type declares `'failed'`, the app sends `'error'` |
709
- | `'cancelled'` | see below | The user declined the request in the ZKProofport app | Reset your UI |
709
+ | `'error'` | yes | The app could not produce a proof — no attestation on that address, sign-in refused, generation failed | Read `error`, show it, let the user start over. `errorCode` (e.g. `'E2007'`) names the cause when the app sent one |
710
+ | `'failed'` | yes | Same meaning and same handling as `'error'`; older app versions send it | Handle it with `'error'` |
711
+ | `'cancelled'` | yes | The user declined the request in the ZKProofport app | Reset your UI |
712
+ | `'expired'` | yes | The app did not answer in time, so the relay answered for it (a little under five minutes after the request) | Offer to start a new request |
710
713
 
711
- `RelayProofResult` declares `status` as `'pending' | 'completed' | 'failed'`, which is narrower than what the relay can deliver, so TypeScript rejects a direct comparison against `'error'`. Widen it once and branch on the string:
714
+ Every terminal status ends the wait: `waitForProof()`, `waitForResult()` and `subscribe()`'s `onResult` all settle on each of the five, so branch on `result.status` rather than assuming success:
712
715
 
713
716
  ```typescript
714
- const status: string = result.status;
717
+ import { isTerminalRelayStatus } from '@zkproofport-app/sdk';
715
718
 
716
- if (status === 'completed') {
717
- // verify it
718
- } else if (status === 'error' || status === 'failed') {
719
- showError(result.error ?? 'Proof generation failed');
719
+ const result = await sdk.waitForProof(relay.requestId);
720
+
721
+ switch (result.status) {
722
+ case 'completed':
723
+ // verify it (Step 7)
724
+ break;
725
+ case 'error':
726
+ case 'failed':
727
+ showError(result.error ?? 'Proof generation failed', result.errorCode);
728
+ break;
729
+ case 'cancelled':
730
+ hideQrDialog();
731
+ break;
732
+ case 'expired':
733
+ offerRetry();
734
+ break;
720
735
  }
721
736
  ```
722
737
 
723
- `waitForProof()` settles on `'completed'`, `'error'` and `'failed'`. It does **not** settle on `'cancelled'` — a cancellation arrives as a status update, and if you ignore it the call sits there until `timeoutMs` expires. Watch for it if you want to drop the QR dialog the moment the user says no:
724
-
725
- ```typescript
726
- const result = await sdk.waitForProof(relay.requestId, {
727
- onStatusChange: (update) => {
728
- if (update.status === 'cancelled') {
729
- // The user declined in the app. This promise will not settle on its own.
730
- hideQrDialog();
731
- }
732
- },
733
- });
734
- ```
738
+ `isTerminalRelayStatus(status)` and `RELAY_TERMINAL_STATUSES` are exported for code that drives `pollResult()` in a loop of its own.
735
739
 
736
- `waitForResult()`, the polling path, is narrower still: it returns only on `'completed'` and `'failed'`, and keeps polling through `'error'` and `'cancelled'` until `timeoutMs`. Prefer `waitForProof()`, or drive `pollResult()` in a loop of your own if you want to decide what counts as terminal.
740
+ The relay answers `'expired'` before the SDK's default `timeoutMs` (300 000 ms) runs out, so with the defaults you get a result to branch on rather than a thrown timeout. If you pass a much shorter `timeoutMs`, the SDK's own timeout can still fire first and the promise rejects.
737
741
 
738
742
  #### What is not on the result
739
743
 
@@ -750,7 +754,8 @@ const result = await sdk.waitForProof(relay.requestId, {
750
754
  | `pollResult()` throws `Request not found or expired` | No — that id is gone | Yes, ask them to start again |
751
755
  | `status: 'error'` / `'failed'` | No — a retry re-runs the same failing thing | Yes: `error` says what went wrong, and it is usually the user's move (connect the right wallet, sign in, use the device holding the licence) |
752
756
  | `status: 'cancelled'` | No | Nothing to say — they just declined |
753
- | `waitForProof()` timeout | Only if the user asks for it | Yes |
757
+ | `status: 'expired'` | Only if the user asks for it | Yes: the app never answered — the QR was not scanned, or the app was closed |
758
+ | `waitForProof()` timeout (only with a `timeoutMs` shorter than the default) | Only if the user asks for it | Yes |
754
759
  | `verifyResponseOnChain()` returns `{ valid: false }` | No | Treat it as a rejected proof, not an outage — Step 7 |
755
760
 
756
761
  #### `ProofResponse` — the shape on-chain verification takes
@@ -1076,7 +1081,8 @@ import type {
1076
1081
  | `ChallengeResponse` | Challenge from the relay: `{ requestId, challenge, expiresAt }` |
1077
1082
  | `WalletSigner` | Signer interface: `{ signMessage(message), getAddress() }` |
1078
1083
  | `RelayProofRequest` | Result of `createRelayRequest()`: `{ requestId, deepLink, status, pollUrl }` |
1079
- | `RelayProofResult` | Result of `waitForProof()` / `waitForResult()` / `pollResult()`: `{ requestId, status, deepLink?, createdAt?, updatedAt?, proof?, publicInputs?, verifierAddress?, chainId?, circuit?, error? }`. `status` is declared as `'pending' \| 'completed' \| 'failed'` but the relay also delivers `'error'` and `'cancelled'` — [Step 6](#step-6-read-the-result) |
1084
+ | `RelayProofResult` | Result of `waitForProof()` / `waitForResult()` / `pollResult()`: `{ requestId, status, deepLink?, createdAt?, updatedAt?, proof?, publicInputs?, verifierAddress?, chainId?, circuit?, error?, errorCode? }`. `status` is a `RelayProofStatus` — [Step 6](#step-6-read-the-result) |
1085
+ | `RelayProofStatus` / `RelayTerminalStatus` | `'pending' \| 'generating'` plus the terminal `'completed' \| 'error' \| 'failed' \| 'cancelled' \| 'expired'` |
1080
1086
 
1081
1087
  The `OidcDomainInputs` interface:
1082
1088
 
@@ -868,7 +868,9 @@ export declare class ProofportSDK {
868
868
  */
869
869
  pollResult(requestId: string): Promise<RelayProofResult>;
870
870
  /**
871
- * Polls the relay until proof is completed or failed, with configurable interval and timeout.
871
+ * Polls the relay until the request reaches a terminal status
872
+ * (`completed`, `error`, `failed`, `cancelled` or `expired`), with
873
+ * configurable interval and timeout. Branch on `result.status`.
872
874
  *
873
875
  * @param requestId - The relay-issued request ID
874
876
  * @param options - Polling options
@@ -894,7 +896,7 @@ export declare class ProofportSDK {
894
896
  * @param requestId - The relay-issued request ID to subscribe to
895
897
  * @param callbacks - Event callbacks for status changes and results
896
898
  * @param callbacks.onStatus - Called on status updates (pending, generating)
897
- * @param callbacks.onResult - Called when proof is completed or failed
899
+ * @param callbacks.onResult - Called once with the terminal result: completed, error, failed, cancelled or expired
898
900
  * @param callbacks.onError - Called on errors
899
901
  * @returns Unsubscribe function to clean up the connection
900
902
  * @throws Error if relayUrl not set or socket.io-client not installed
package/dist/index.d.ts CHANGED
@@ -34,5 +34,6 @@ export { COINBASE_ATTESTATION_PUBLIC_INPUT_LAYOUT, COINBASE_COUNTRY_PUBLIC_INPUT
34
34
  export type { CircuitId, CircuitSupportStatus } from './circuits';
35
35
  export { CIRCUIT_ACTION_BINDING, circuitActionBinding, } from './circuits';
36
36
  export type { CircuitActionBinding } from './circuits';
37
- export type { CircuitType, ProofRequestStatus, CoinbaseKycInputs, ActionBoundInputs, GiwaAttestationInputs, DojangPlaygroundInputs, TypedAction, CoinbaseCountryInputs, OidcDomainInputs, MdlKrOwnershipInputs, MdlKrAgeInputs, MdlKrRegionInputs, CircuitInputs, ProofRequest, ProofResponse, QRCodeOptions, VerifierContract, ProofportConfig, ChallengeResponse, WalletSigner, RelayProofRequest, RelayProofResult, SDKEnvironment, } from './types';
37
+ export type { CircuitType, ProofRequestStatus, CoinbaseKycInputs, ActionBoundInputs, GiwaAttestationInputs, DojangPlaygroundInputs, TypedAction, CoinbaseCountryInputs, OidcDomainInputs, MdlKrOwnershipInputs, MdlKrAgeInputs, MdlKrRegionInputs, CircuitInputs, ProofRequest, ProofResponse, QRCodeOptions, VerifierContract, ProofportConfig, ChallengeResponse, WalletSigner, RelayProofRequest, RelayProofResult, RelayProofStatus, RelayTerminalStatus, SDKEnvironment, } from './types';
38
+ export { RELAY_TERMINAL_STATUSES, isTerminalRelayStatus } from './relayStatus';
38
39
  export { validateTypedAction, parseTypedAction } from './typedAction';
package/dist/index.esm.js CHANGED
@@ -4916,6 +4916,17 @@ async function verifyProofOffChain(circuit, proof, publicInputs, options = {}) {
4916
4916
  }
4917
4917
  }
4918
4918
 
4919
+ /**
4920
+ * The statuses a relay request ends in, as a runtime list. `satisfies` keeps it
4921
+ * in step with the `RelayTerminalStatus` type in both directions: a status
4922
+ * added to the type and not here, or here and not in the type, fails to compile.
4923
+ */
4924
+ const RELAY_TERMINAL_STATUSES = ['completed', 'error', 'failed', 'cancelled', 'expired'];
4925
+ /** True when `status` is one a relay request ends in. */
4926
+ function isTerminalRelayStatus(status) {
4927
+ return RELAY_TERMINAL_STATUSES.includes(status);
4928
+ }
4929
+
4919
4930
  /**
4920
4931
  * Proofport SDK - Main class
4921
4932
  */
@@ -6041,7 +6052,9 @@ class ProofportSDK {
6041
6052
  return await response.json();
6042
6053
  }
6043
6054
  /**
6044
- * Polls the relay until proof is completed or failed, with configurable interval and timeout.
6055
+ * Polls the relay until the request reaches a terminal status
6056
+ * (`completed`, `error`, `failed`, `cancelled` or `expired`), with
6057
+ * configurable interval and timeout. Branch on `result.status`.
6045
6058
  *
6046
6059
  * @param requestId - The relay-issued request ID
6047
6060
  * @param options - Polling options
@@ -6062,7 +6075,10 @@ class ProofportSDK {
6062
6075
  lastStatus = result.status;
6063
6076
  options.onStatusChange?.(result);
6064
6077
  }
6065
- if (result.status === 'completed' || result.status === 'failed') {
6078
+ // Every terminal status ends the wait, not only success: an app error,
6079
+ // a cancellation and a relay-side timeout are answers too, and polling
6080
+ // past them would only end in this method's own timeout.
6081
+ if (isTerminalRelayStatus(result.status)) {
6066
6082
  return result;
6067
6083
  }
6068
6084
  await new Promise(resolve => setTimeout(resolve, interval));
@@ -6080,7 +6096,7 @@ class ProofportSDK {
6080
6096
  * @param requestId - The relay-issued request ID to subscribe to
6081
6097
  * @param callbacks - Event callbacks for status changes and results
6082
6098
  * @param callbacks.onStatus - Called on status updates (pending, generating)
6083
- * @param callbacks.onResult - Called when proof is completed or failed
6099
+ * @param callbacks.onResult - Called once with the terminal result: completed, error, failed, cancelled or expired
6084
6100
  * @param callbacks.onError - Called on errors
6085
6101
  * @returns Unsubscribe function to clean up the connection
6086
6102
  * @throws Error if relayUrl not set or socket.io-client not installed
@@ -6287,5 +6303,5 @@ class ProofportSDK {
6287
6303
  }
6288
6304
  }
6289
6305
 
6290
- export { ALL_CIRCUIT_IDS, CIRCUIT_ACTION_BINDING, CIRCUIT_IDS, CIRCUIT_SUPPORT_STATUS, CIRCUIT_VK_PATHS, COINBASE_ATTESTATION_PUBLIC_INPUT_LAYOUT, COINBASE_COUNTRY_PUBLIC_INPUT_LAYOUT, EXPERIMENTAL_CIRCUIT_IDS, MDL_KR_PUBLIC_INPUT_LAYOUT, OIDC_DOMAIN_ATTESTATION_PUBLIC_INPUT_LAYOUT, PLANNED_CIRCUIT_IDS, ProofportSDK, SUPPORTED_CIRCUIT_IDS, circuitActionBinding, ProofportSDK as default, extractDomainFromPublicInputs, extractNullifierFromPublicInputs, extractScopeFromPublicInputs, getCircuitSupportStatus, isCircuitId, isSupportedCircuitId, parseTypedAction, validateTypedAction, verifyProofOffChain };
6306
+ export { ALL_CIRCUIT_IDS, CIRCUIT_ACTION_BINDING, CIRCUIT_IDS, CIRCUIT_SUPPORT_STATUS, CIRCUIT_VK_PATHS, COINBASE_ATTESTATION_PUBLIC_INPUT_LAYOUT, COINBASE_COUNTRY_PUBLIC_INPUT_LAYOUT, EXPERIMENTAL_CIRCUIT_IDS, MDL_KR_PUBLIC_INPUT_LAYOUT, OIDC_DOMAIN_ATTESTATION_PUBLIC_INPUT_LAYOUT, PLANNED_CIRCUIT_IDS, ProofportSDK, RELAY_TERMINAL_STATUSES, SUPPORTED_CIRCUIT_IDS, circuitActionBinding, ProofportSDK as default, extractDomainFromPublicInputs, extractNullifierFromPublicInputs, extractScopeFromPublicInputs, getCircuitSupportStatus, isCircuitId, isSupportedCircuitId, isTerminalRelayStatus, parseTypedAction, validateTypedAction, verifyProofOffChain };
6291
6307
  //# sourceMappingURL=index.esm.js.map