@zkproofport-app/sdk 0.4.1 → 0.4.3
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 +33 -25
- package/dist/ProofportSDK.d.ts +4 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.esm.js +27 -4
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +28 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +27 -4
- package/dist/index.mjs.map +1 -1
- package/dist/relayStatus.d.ts +9 -0
- package/dist/types.d.ts +20 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -477,6 +477,8 @@ const relay = await sdk.createRelayRequest('coinbase_attestation', {
|
|
|
477
477
|
|
|
478
478
|
Every field of the third argument is optional: `message`, `dappName` and `dappIcon` are shown to the user in the ZKProofport app, `nonce` is a value of your own choosing that the relay refuses to accept twice, and `returnScheme` is described next.
|
|
479
479
|
|
|
480
|
+
The relay never reads your circuit inputs. So that ZKProofport can count requests per app, the SDK also sends `scope` alongside them, unchanged. The proof itself uses the scope in your inputs.
|
|
481
|
+
|
|
480
482
|
#### Switching back: `returnScheme`
|
|
481
483
|
|
|
482
484
|
When ZKProofport finishes a proof, the user is sitting in the ZKProofport app. `returnScheme` answers one question: **which app should come back to the foreground?**
|
|
@@ -692,7 +694,8 @@ When you are done, `sdk.disconnect()` closes any open socket.
|
|
|
692
694
|
| `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
695
|
| `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
696
|
| `chainId` | `number` | `'completed'` | The chain that `verifierAddress` lives on. Same rule: forward it. |
|
|
695
|
-
| `error` | `string` |
|
|
697
|
+
| `error` | `string` | `'error'`, `'failed'`, `'expired'` | Human-readable reason from the mobile app or the relay. |
|
|
698
|
+
| `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
699
|
| `deepLink` | `string` | polling path only | The deep link the request was created with. |
|
|
697
700
|
| `createdAt`, `updatedAt` | `string` | polling path only | ISO timestamps of creation and last update. |
|
|
698
701
|
|
|
@@ -703,37 +706,40 @@ The last three come from the relay's polling endpoint. `waitForProof()` normally
|
|
|
703
706
|
| `status` | Terminal | What happened | What you do |
|
|
704
707
|
|----------|----------|---------------|-------------|
|
|
705
708
|
| `'pending'` | no | The request exists; no proof yet | Keep waiting — `waitForProof()` does that for you |
|
|
709
|
+
| `'generating'` | no | The app is producing the proof | Keep waiting |
|
|
706
710
|
| `'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'
|
|
709
|
-
| `'cancelled'` |
|
|
711
|
+
| `'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 |
|
|
712
|
+
| `'failed'` | yes | Same meaning and same handling as `'error'`; older app versions send it | Handle it with `'error'` |
|
|
713
|
+
| `'cancelled'` | yes | The user declined the request in the ZKProofport app | Reset your UI |
|
|
714
|
+
| `'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
715
|
|
|
711
|
-
|
|
716
|
+
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
717
|
|
|
713
718
|
```typescript
|
|
714
|
-
|
|
719
|
+
import { isTerminalRelayStatus } from '@zkproofport-app/sdk';
|
|
720
|
+
|
|
721
|
+
const result = await sdk.waitForProof(relay.requestId);
|
|
715
722
|
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
723
|
+
switch (result.status) {
|
|
724
|
+
case 'completed':
|
|
725
|
+
// verify it (Step 7)
|
|
726
|
+
break;
|
|
727
|
+
case 'error':
|
|
728
|
+
case 'failed':
|
|
729
|
+
showError(result.error ?? 'Proof generation failed', result.errorCode);
|
|
730
|
+
break;
|
|
731
|
+
case 'cancelled':
|
|
732
|
+
hideQrDialog();
|
|
733
|
+
break;
|
|
734
|
+
case 'expired':
|
|
735
|
+
offerRetry();
|
|
736
|
+
break;
|
|
720
737
|
}
|
|
721
738
|
```
|
|
722
739
|
|
|
723
|
-
`
|
|
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
|
-
```
|
|
740
|
+
`isTerminalRelayStatus(status)` and `RELAY_TERMINAL_STATUSES` are exported for code that drives `pollResult()` in a loop of its own.
|
|
735
741
|
|
|
736
|
-
`
|
|
742
|
+
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
743
|
|
|
738
744
|
#### What is not on the result
|
|
739
745
|
|
|
@@ -750,7 +756,8 @@ const result = await sdk.waitForProof(relay.requestId, {
|
|
|
750
756
|
| `pollResult()` throws `Request not found or expired` | No — that id is gone | Yes, ask them to start again |
|
|
751
757
|
| `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
758
|
| `status: 'cancelled'` | No | Nothing to say — they just declined |
|
|
753
|
-
| `
|
|
759
|
+
| `status: 'expired'` | Only if the user asks for it | Yes: the app never answered — the QR was not scanned, or the app was closed |
|
|
760
|
+
| `waitForProof()` timeout (only with a `timeoutMs` shorter than the default) | Only if the user asks for it | Yes |
|
|
754
761
|
| `verifyResponseOnChain()` returns `{ valid: false }` | No | Treat it as a rejected proof, not an outage — Step 7 |
|
|
755
762
|
|
|
756
763
|
#### `ProofResponse` — the shape on-chain verification takes
|
|
@@ -1076,7 +1083,8 @@ import type {
|
|
|
1076
1083
|
| `ChallengeResponse` | Challenge from the relay: `{ requestId, challenge, expiresAt }` |
|
|
1077
1084
|
| `WalletSigner` | Signer interface: `{ signMessage(message), getAddress() }` |
|
|
1078
1085
|
| `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
|
|
1086
|
+
| `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) |
|
|
1087
|
+
| `RelayProofStatus` / `RelayTerminalStatus` | `'pending' \| 'generating'` plus the terminal `'completed' \| 'error' \| 'failed' \| 'cancelled' \| 'expired'` |
|
|
1080
1088
|
|
|
1081
1089
|
The `OidcDomainInputs` interface:
|
|
1082
1090
|
|
package/dist/ProofportSDK.d.ts
CHANGED
|
@@ -868,7 +868,9 @@ export declare class ProofportSDK {
|
|
|
868
868
|
*/
|
|
869
869
|
pollResult(requestId: string): Promise<RelayProofResult>;
|
|
870
870
|
/**
|
|
871
|
-
* Polls the relay until
|
|
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
|
|
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
|
*/
|
|
@@ -5978,6 +5989,13 @@ class ProofportSDK {
|
|
|
5978
5989
|
inputs,
|
|
5979
5990
|
challenge,
|
|
5980
5991
|
};
|
|
5992
|
+
// The relay never reads `inputs`, so the scope is also sent on the envelope,
|
|
5993
|
+
// where the relay counts requests per scope. The app proves the scope inside
|
|
5994
|
+
// `inputs` and uses the envelope copy only when `inputs` has none; both are
|
|
5995
|
+
// the same string here.
|
|
5996
|
+
const scope = inputs.scope;
|
|
5997
|
+
if (typeof scope === 'string' && scope.length > 0)
|
|
5998
|
+
body.scope = scope;
|
|
5981
5999
|
// Sign challenge for circuits that require wallet signature
|
|
5982
6000
|
if (needsSignature && this.signer) {
|
|
5983
6001
|
body.signature = await this.signer.signMessage(challenge);
|
|
@@ -6041,7 +6059,9 @@ class ProofportSDK {
|
|
|
6041
6059
|
return await response.json();
|
|
6042
6060
|
}
|
|
6043
6061
|
/**
|
|
6044
|
-
* Polls the relay until
|
|
6062
|
+
* Polls the relay until the request reaches a terminal status
|
|
6063
|
+
* (`completed`, `error`, `failed`, `cancelled` or `expired`), with
|
|
6064
|
+
* configurable interval and timeout. Branch on `result.status`.
|
|
6045
6065
|
*
|
|
6046
6066
|
* @param requestId - The relay-issued request ID
|
|
6047
6067
|
* @param options - Polling options
|
|
@@ -6062,7 +6082,10 @@ class ProofportSDK {
|
|
|
6062
6082
|
lastStatus = result.status;
|
|
6063
6083
|
options.onStatusChange?.(result);
|
|
6064
6084
|
}
|
|
6065
|
-
|
|
6085
|
+
// Every terminal status ends the wait, not only success: an app error,
|
|
6086
|
+
// a cancellation and a relay-side timeout are answers too, and polling
|
|
6087
|
+
// past them would only end in this method's own timeout.
|
|
6088
|
+
if (isTerminalRelayStatus(result.status)) {
|
|
6066
6089
|
return result;
|
|
6067
6090
|
}
|
|
6068
6091
|
await new Promise(resolve => setTimeout(resolve, interval));
|
|
@@ -6080,7 +6103,7 @@ class ProofportSDK {
|
|
|
6080
6103
|
* @param requestId - The relay-issued request ID to subscribe to
|
|
6081
6104
|
* @param callbacks - Event callbacks for status changes and results
|
|
6082
6105
|
* @param callbacks.onStatus - Called on status updates (pending, generating)
|
|
6083
|
-
* @param callbacks.onResult - Called
|
|
6106
|
+
* @param callbacks.onResult - Called once with the terminal result: completed, error, failed, cancelled or expired
|
|
6084
6107
|
* @param callbacks.onError - Called on errors
|
|
6085
6108
|
* @returns Unsubscribe function to clean up the connection
|
|
6086
6109
|
* @throws Error if relayUrl not set or socket.io-client not installed
|
|
@@ -6287,5 +6310,5 @@ class ProofportSDK {
|
|
|
6287
6310
|
}
|
|
6288
6311
|
}
|
|
6289
6312
|
|
|
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 };
|
|
6313
|
+
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
6314
|
//# sourceMappingURL=index.esm.js.map
|