@zkproofport-app/sdk 0.5.0-beta.1 → 0.5.0-beta.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 +32 -17
- package/dist/ProofportSDK.d.ts +59 -10
- package/dist/constants.d.ts +43 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.esm.js +255 -45
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +297 -43
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +255 -45
- package/dist/index.mjs.map +1 -1
- package/dist/offChainVerifier.d.ts +13 -0
- package/dist/types.d.ts +8 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -25,6 +25,49 @@ const RELAY_URLS = {
|
|
|
25
25
|
staging: 'https://stg-relay.zkproofport.app',
|
|
26
26
|
local: 'http://localhost:4001',
|
|
27
27
|
};
|
|
28
|
+
/**
|
|
29
|
+
* The chain each circuit is verified on, per environment. Complete: a circuit
|
|
30
|
+
* added to the SDK is a compile error here until somebody names its chain.
|
|
31
|
+
*
|
|
32
|
+
* Mirrors the mobile app's `CIRCUIT_NETWORKS` (proofport-app
|
|
33
|
+
* src/config/contracts.ts), because a proof is checked where the app said its
|
|
34
|
+
* verifier is: Base for the Coinbase and OIDC circuits, GIWA Sepolia for GIWA
|
|
35
|
+
* and Dojang (testnet-only), Base Sepolia for Korea Mobile ID (testnet-only).
|
|
36
|
+
* The ADDRESS on that chain always comes from core's pinned table, never from
|
|
37
|
+
* a proof response.
|
|
38
|
+
*/
|
|
39
|
+
const VERIFICATION_CHAINS = {
|
|
40
|
+
production: {
|
|
41
|
+
coinbase_attestation: 8453,
|
|
42
|
+
coinbase_country_attestation: 8453,
|
|
43
|
+
oidc_domain_attestation: 8453,
|
|
44
|
+
giwa_attestation: 91342,
|
|
45
|
+
dojang_playground: 91342,
|
|
46
|
+
mdl_kr_ownership: 84532,
|
|
47
|
+
mdl_kr_age: 84532,
|
|
48
|
+
mdl_kr_region: 84532,
|
|
49
|
+
},
|
|
50
|
+
staging: {
|
|
51
|
+
coinbase_attestation: 84532,
|
|
52
|
+
coinbase_country_attestation: 84532,
|
|
53
|
+
oidc_domain_attestation: 84532,
|
|
54
|
+
giwa_attestation: 91342,
|
|
55
|
+
dojang_playground: 91342,
|
|
56
|
+
mdl_kr_ownership: 84532,
|
|
57
|
+
mdl_kr_age: 84532,
|
|
58
|
+
mdl_kr_region: 84532,
|
|
59
|
+
},
|
|
60
|
+
local: {
|
|
61
|
+
coinbase_attestation: 84532,
|
|
62
|
+
coinbase_country_attestation: 84532,
|
|
63
|
+
oidc_domain_attestation: 84532,
|
|
64
|
+
giwa_attestation: 91342,
|
|
65
|
+
dojang_playground: 91342,
|
|
66
|
+
mdl_kr_ownership: 84532,
|
|
67
|
+
mdl_kr_age: 84532,
|
|
68
|
+
mdl_kr_region: 84532,
|
|
69
|
+
},
|
|
70
|
+
};
|
|
28
71
|
/**
|
|
29
72
|
* Default deep link URL scheme for ZKProofport mobile app.
|
|
30
73
|
* Used to construct deep link URLs that open the mobile app.
|
|
@@ -83,8 +126,10 @@ const CIRCUIT_METADATA = {
|
|
|
83
126
|
oidc_domain_attestation: {
|
|
84
127
|
name: 'OIDC Domain',
|
|
85
128
|
description: 'Prove email domain affiliation via OIDC JWT',
|
|
86
|
-
|
|
87
|
-
|
|
129
|
+
// v2: 148 v1 fields, then aud_hash (32), nonce_mode (1), nonce_binding
|
|
130
|
+
// (32), now (1). oidc-domain-attestation/src/main.nr.
|
|
131
|
+
publicInputsCount: 214,
|
|
132
|
+
publicInputNames: ['pubkey_modulus_limbs', 'domain', 'scope', 'nullifier', 'provider', 'aud_hash', 'nonce_mode', 'nonce_binding', 'now'],
|
|
88
133
|
},
|
|
89
134
|
// Planned circuit — the identifier is reserved and the circuit exists, but it
|
|
90
135
|
// is not officially supported yet. See CIRCUIT_SUPPORT_STATUS in ./circuits.
|
|
@@ -1098,6 +1143,12 @@ async function fetchVerificationKey(circuit, timeoutMs) {
|
|
|
1098
1143
|
* Needs no setup from the caller: the verifier ships with this SDK and is
|
|
1099
1144
|
* loaded on first use.
|
|
1100
1145
|
*
|
|
1146
|
+
* For `oidc_domain_attestation` it first checks the token's audience, nonce and
|
|
1147
|
+
* time (core's `checkOidcPolicy`, against `options.request` when given) and the
|
|
1148
|
+
* proof's RSA key against the provider's published JWKS (core's
|
|
1149
|
+
* `checkOidcProviderKey`); any refusal, or a JWKS that cannot be fetched, is
|
|
1150
|
+
* `{ valid: false }`.
|
|
1151
|
+
*
|
|
1101
1152
|
* @param circuit - Canonical circuit identifier
|
|
1102
1153
|
* @param proof - Proof bytes as hex, WITHOUT public inputs (as the relay sends it)
|
|
1103
1154
|
* @param publicInputs - Public inputs as hex strings, in circuit order
|
|
@@ -1116,6 +1167,18 @@ async function fetchVerificationKey(circuit, timeoutMs) {
|
|
|
1116
1167
|
*/
|
|
1117
1168
|
async function verifyProofOffChain(circuit, proof, publicInputs, options = {}) {
|
|
1118
1169
|
const timeoutMs = options.timeoutMs ?? 30000;
|
|
1170
|
+
if (!circuits.isCircuitId(circuit)) {
|
|
1171
|
+
return { valid: false, error: `Unknown circuit '${circuit}'. Known: ${circuits.ALL_CIRCUIT_IDS.join(', ')}.` };
|
|
1172
|
+
}
|
|
1173
|
+
// Before Barretenberg, and for the same reason as on-chain: a proof can be
|
|
1174
|
+
// mathematically valid and still mean nothing, because some circuits take
|
|
1175
|
+
// their trust anchor as a public input the prover chooses. For OIDC that is
|
|
1176
|
+
// the RSA key -- see core's oidcProviderKeys. Checked here so a dApp that
|
|
1177
|
+
// verifies off-chain gets the same answer as one that verifies on-chain.
|
|
1178
|
+
const issuer = await core.checkProofIssuer(circuit, publicInputs, { request: options.request });
|
|
1179
|
+
if (!issuer.ok) {
|
|
1180
|
+
return { valid: false, error: issuer.error };
|
|
1181
|
+
}
|
|
1119
1182
|
// A REQUIRED dependency, loaded lazily.
|
|
1120
1183
|
//
|
|
1121
1184
|
// It was briefly an optional peer dependency, on the reasoning that the WASM
|
|
@@ -1254,24 +1317,41 @@ class ProofportSDK {
|
|
|
1254
1317
|
*/
|
|
1255
1318
|
constructor(config = {}) {
|
|
1256
1319
|
this.pendingRequests = new Map();
|
|
1320
|
+
/**
|
|
1321
|
+
* requestId -> scope of the relay requests this instance created, so that
|
|
1322
|
+
* verifyResponse* can check an OIDC proof's request-bound nonce without the
|
|
1323
|
+
* dApp passing the request back in. Oldest entries go first past
|
|
1324
|
+
* {@link ProofportSDK.MAX_REMEMBERED_RELAY_REQUESTS}.
|
|
1325
|
+
*/
|
|
1326
|
+
this.relayRequests = new Map();
|
|
1257
1327
|
this.signer = null;
|
|
1258
1328
|
this.socket = null;
|
|
1329
|
+
/**
|
|
1330
|
+
* Set by {@link ProofportSDK.create} from its environment preset. It decides
|
|
1331
|
+
* which chain a proof is verified on when the dApp configured no verifier
|
|
1332
|
+
* for the circuit; a custom-config SDK has none and must configure one.
|
|
1333
|
+
*/
|
|
1334
|
+
this.environment = null;
|
|
1259
1335
|
this.config = {
|
|
1260
1336
|
scheme: config.scheme || DEFAULT_SCHEME,
|
|
1261
1337
|
verifiers: config.verifiers || {},
|
|
1262
1338
|
};
|
|
1263
1339
|
this.relayUrl = config.relayUrl || '';
|
|
1340
|
+
if (config.environment !== undefined) {
|
|
1341
|
+
if (!Object.prototype.hasOwnProperty.call(VERIFICATION_CHAINS, config.environment)) {
|
|
1342
|
+
throw new Error(`Unknown environment '${config.environment}'. Known: ${Object.keys(VERIFICATION_CHAINS).join(', ')}.`);
|
|
1343
|
+
}
|
|
1344
|
+
this.environment = config.environment;
|
|
1345
|
+
}
|
|
1264
1346
|
}
|
|
1265
1347
|
// ============ Request Creation ============
|
|
1266
1348
|
/**
|
|
1267
1349
|
* @internal
|
|
1268
|
-
* Creates a
|
|
1269
|
-
*
|
|
1270
|
-
* Generates a proof request for verifying Coinbase KYC status without revealing
|
|
1271
|
-
* the actual attestation data. The proof confirms the user has passed Coinbase KYC
|
|
1272
|
-
* while maintaining privacy through zero-knowledge proofs.
|
|
1350
|
+
* Creates a proof request for a circuit whose dapp-side input is a scope
|
|
1351
|
+
* (Coinbase KYC, OIDC domain, GIWA, Dojang), keeping that circuit's id.
|
|
1273
1352
|
*
|
|
1274
|
-
* @param
|
|
1353
|
+
* @param circuit - The circuit requested; it is the request's circuit
|
|
1354
|
+
* @param inputs - Circuit inputs; `scope` is required (and `domain` for OIDC)
|
|
1275
1355
|
* @param inputs.scope - Application-specific scope (e.g., domain name)
|
|
1276
1356
|
* @param options - Request configuration options
|
|
1277
1357
|
|
|
@@ -1286,7 +1366,7 @@ class ProofportSDK {
|
|
|
1286
1366
|
*
|
|
1287
1367
|
* @example
|
|
1288
1368
|
* ```typescript
|
|
1289
|
-
* const request = sdk.
|
|
1369
|
+
* const request = sdk.createScopedRequest('coinbase_attestation', {
|
|
1290
1370
|
* scope: 'myapp.com'
|
|
1291
1371
|
* }, {
|
|
1292
1372
|
* dappName: 'My DApp',
|
|
@@ -1296,13 +1376,34 @@ class ProofportSDK {
|
|
|
1296
1376
|
* const deepLink = sdk.getDeepLinkUrl(request);
|
|
1297
1377
|
* ```
|
|
1298
1378
|
*/
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1379
|
+
createScopedRequest(circuit, inputs, options = {}) {
|
|
1380
|
+
const scope = inputs.scope;
|
|
1381
|
+
if (typeof scope !== 'string' || scope.trim() === '') {
|
|
1382
|
+
throw new Error(`scope is required for ${circuit} circuit`);
|
|
1383
|
+
}
|
|
1384
|
+
if (circuit === 'oidc_domain_attestation') {
|
|
1385
|
+
const domain = inputs.domain;
|
|
1386
|
+
if (typeof domain !== 'string' || domain.trim() === '') {
|
|
1387
|
+
throw new Error('domain is required for oidc_domain_attestation circuit');
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
const action = inputs.action;
|
|
1391
|
+
const binding = circuits.circuitActionBinding(circuit);
|
|
1392
|
+
if (binding === 'none' && action !== undefined) {
|
|
1393
|
+
throw new Error(`${circuit} has no action inputs, so an action sent with it would not be proved.`);
|
|
1394
|
+
}
|
|
1395
|
+
if (binding === 'required' || (binding === 'optional' && action !== undefined)) {
|
|
1396
|
+
const actionError = typedAction.validateTypedAction(action);
|
|
1397
|
+
if (actionError)
|
|
1398
|
+
throw new Error(`${actionError} (circuit: ${circuit})`);
|
|
1302
1399
|
}
|
|
1303
1400
|
const request = {
|
|
1304
1401
|
requestId: generateRequestId(),
|
|
1305
|
-
circuit
|
|
1402
|
+
// The circuit asked for, always. This used to be the literal
|
|
1403
|
+
// 'coinbase_attestation', and every circuit that was not country or mDL
|
|
1404
|
+
// was routed here -- a GIWA, Dojang or OIDC request silently became a
|
|
1405
|
+
// Coinbase KYC request.
|
|
1406
|
+
circuit,
|
|
1306
1407
|
inputs,
|
|
1307
1408
|
message: options.message,
|
|
1308
1409
|
dappName: options.dappName,
|
|
@@ -1399,16 +1500,17 @@ class ProofportSDK {
|
|
|
1399
1500
|
* ```
|
|
1400
1501
|
*/
|
|
1401
1502
|
createProofRequest(circuit, inputs, options = {}) {
|
|
1402
|
-
if (circuit
|
|
1403
|
-
|
|
1404
|
-
}
|
|
1405
|
-
else if (circuit === 'mdl_kr_ownership' ||
|
|
1406
|
-
circuit === 'mdl_kr_age' ||
|
|
1407
|
-
circuit === 'mdl_kr_region') {
|
|
1408
|
-
return this.createMdlKrRequest(circuit, inputs, options);
|
|
1503
|
+
if (!circuits.isCircuitId(circuit)) {
|
|
1504
|
+
throw new Error(`Unknown circuit '${circuit}'. Known: ${circuits.ALL_CIRCUIT_IDS.join(', ')}.`);
|
|
1409
1505
|
}
|
|
1410
|
-
|
|
1411
|
-
|
|
1506
|
+
const builder = ProofportSDK.REQUEST_BUILDERS[circuit];
|
|
1507
|
+
switch (builder) {
|
|
1508
|
+
case 'country':
|
|
1509
|
+
return this.createCoinbaseCountryRequest(inputs, options);
|
|
1510
|
+
case 'mdl':
|
|
1511
|
+
return this.createMdlKrRequest(circuit, inputs, options);
|
|
1512
|
+
case 'scoped':
|
|
1513
|
+
return this.createScopedRequest(circuit, inputs, options);
|
|
1412
1514
|
}
|
|
1413
1515
|
}
|
|
1414
1516
|
/**
|
|
@@ -1783,10 +1885,66 @@ class ProofportSDK {
|
|
|
1783
1885
|
* }
|
|
1784
1886
|
* ```
|
|
1785
1887
|
*/
|
|
1786
|
-
async verifyOnChain(circuit, proof, publicInputs, providerOrSigner) {
|
|
1888
|
+
async verifyOnChain(circuit, proof, publicInputs, providerOrSigner, options = {}) {
|
|
1787
1889
|
const parsedProof = core.parseProofForOnChain(proof, publicInputs, publicInputs.length);
|
|
1788
|
-
|
|
1789
|
-
|
|
1890
|
+
return core.verifyProofOnChain(circuit, parsedProof, providerOrSigner, this.verifierTarget(circuit), undefined, {
|
|
1891
|
+
request: options.request,
|
|
1892
|
+
});
|
|
1893
|
+
}
|
|
1894
|
+
/**
|
|
1895
|
+
* The request an `oidc_domain_attestation` response answers: the one the
|
|
1896
|
+
* caller passed, else the relay request this instance created under the
|
|
1897
|
+
* response's requestId. `{ error }` when there is none, or when the two
|
|
1898
|
+
* disagree -- an OIDC proof made with a request-bound nonce is only
|
|
1899
|
+
* meaningful against the request it was bound to, so a response this SDK
|
|
1900
|
+
* cannot place is refused rather than checked without it.
|
|
1901
|
+
*/
|
|
1902
|
+
oidcRequestFor(response, explicit) {
|
|
1903
|
+
if (explicit !== undefined) {
|
|
1904
|
+
if (explicit === null || typeof explicit !== 'object' || explicit.requestId !== response.requestId) {
|
|
1905
|
+
return {
|
|
1906
|
+
error: `The request passed in (${JSON.stringify(explicit?.requestId)}) is not the one this response answers (${JSON.stringify(response.requestId)}).`,
|
|
1907
|
+
};
|
|
1908
|
+
}
|
|
1909
|
+
return { request: explicit };
|
|
1910
|
+
}
|
|
1911
|
+
const remembered = this.relayRequests.get(response.requestId);
|
|
1912
|
+
if (!remembered) {
|
|
1913
|
+
return {
|
|
1914
|
+
error: `No request ${JSON.stringify(response.requestId)} was created by this SDK instance, so the OIDC proof's ` +
|
|
1915
|
+
'nonce cannot be checked against it. Pass { request: { scope, requestId } } -- the scope and relay ' +
|
|
1916
|
+
'requestId of the request you created.',
|
|
1917
|
+
};
|
|
1918
|
+
}
|
|
1919
|
+
return { request: remembered };
|
|
1920
|
+
}
|
|
1921
|
+
/** @internal Remember a relay request's scope for verifyResponse*. */
|
|
1922
|
+
rememberRelayRequest(requestId, scope) {
|
|
1923
|
+
if (typeof requestId !== 'string' || typeof scope !== 'string')
|
|
1924
|
+
return;
|
|
1925
|
+
this.relayRequests.delete(requestId);
|
|
1926
|
+
this.relayRequests.set(requestId, { scope, requestId });
|
|
1927
|
+
while (this.relayRequests.size > ProofportSDK.MAX_REMEMBERED_RELAY_REQUESTS) {
|
|
1928
|
+
const oldest = this.relayRequests.keys().next().value;
|
|
1929
|
+
this.relayRequests.delete(oldest);
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
/**
|
|
1933
|
+
* The verifier for a circuit: the one the dApp configured, otherwise the
|
|
1934
|
+
* pinned deployment on the chain this SDK's environment verifies that
|
|
1935
|
+
* circuit on. `undefined` when neither exists, which core reports as an
|
|
1936
|
+
* error. Never anything a proof response said.
|
|
1937
|
+
*/
|
|
1938
|
+
verifierTarget(circuit) {
|
|
1939
|
+
const configured = this.config.verifiers[circuit];
|
|
1940
|
+
if (configured)
|
|
1941
|
+
return configured;
|
|
1942
|
+
if (this.environment === null)
|
|
1943
|
+
return undefined;
|
|
1944
|
+
const chains = VERIFICATION_CHAINS[this.environment];
|
|
1945
|
+
if (!Object.prototype.hasOwnProperty.call(chains, circuit))
|
|
1946
|
+
return undefined;
|
|
1947
|
+
return { chainId: chains[circuit] };
|
|
1790
1948
|
}
|
|
1791
1949
|
/**
|
|
1792
1950
|
* Verifies a proof response on-chain using the deployed verifier contract.
|
|
@@ -1796,6 +1954,9 @@ class ProofportSDK {
|
|
|
1796
1954
|
*
|
|
1797
1955
|
* @param response - ProofResponse object from parseResponse()
|
|
1798
1956
|
* @param providerOrSigner - ethers v6 Provider or Signer (defaults to base mainnet public RPC)
|
|
1957
|
+
* @param options.request - For `oidc_domain_attestation`: the `{ scope, requestId }`
|
|
1958
|
+
* the response answers. Not needed for a relay request this SDK instance
|
|
1959
|
+
* created; an OIDC response this instance cannot place is refused without it.
|
|
1799
1960
|
*
|
|
1800
1961
|
* @returns Promise resolving to verification result with valid boolean and optional error message
|
|
1801
1962
|
*
|
|
@@ -1822,17 +1983,26 @@ class ProofportSDK {
|
|
|
1822
1983
|
* });
|
|
1823
1984
|
* ```
|
|
1824
1985
|
*/
|
|
1825
|
-
async verifyResponseOnChain(response, providerOrSigner) {
|
|
1986
|
+
async verifyResponseOnChain(response, providerOrSigner, options = {}) {
|
|
1826
1987
|
if (response.status !== 'completed' || !response.proof || !response.publicInputs) {
|
|
1827
1988
|
return { valid: false, error: 'Invalid or incomplete response' };
|
|
1828
1989
|
}
|
|
1990
|
+
let request;
|
|
1991
|
+
if (response.circuit === 'oidc_domain_attestation') {
|
|
1992
|
+
const found = this.oidcRequestFor(response, options.request);
|
|
1993
|
+
if ('error' in found)
|
|
1994
|
+
return { valid: false, error: found.error };
|
|
1995
|
+
request = found.request;
|
|
1996
|
+
}
|
|
1829
1997
|
const parsedProof = core.parseProofForOnChain(response.proof, response.publicInputs, response.publicInputs.length);
|
|
1830
|
-
|
|
1831
|
-
|
|
1998
|
+
// The response's verifierAddress and chainId are a claim to check, never
|
|
1999
|
+
// the contract to call: whoever wrote the response would otherwise pick
|
|
2000
|
+
// the judge. A claim that differs from the pinned or configured verifier
|
|
2001
|
+
// is refused.
|
|
2002
|
+
return core.verifyProofOnChain(response.circuit, parsedProof, providerOrSigner, this.verifierTarget(response.circuit), {
|
|
1832
2003
|
verifierAddress: response.verifierAddress,
|
|
1833
2004
|
chainId: response.chainId,
|
|
1834
|
-
};
|
|
1835
|
-
return core.verifyProofOnChain(response.circuit, parsedProof, providerOrSigner, customVerifier, responseVerifier);
|
|
2005
|
+
}, { request });
|
|
1836
2006
|
}
|
|
1837
2007
|
/**
|
|
1838
2008
|
* Verifies a proof response off-chain, against the circuit's verification key.
|
|
@@ -1862,7 +2032,14 @@ class ProofportSDK {
|
|
|
1862
2032
|
if (response.status !== 'completed' || !response.proof || !response.publicInputs) {
|
|
1863
2033
|
return { valid: false, error: 'Invalid or incomplete response' };
|
|
1864
2034
|
}
|
|
1865
|
-
|
|
2035
|
+
let request;
|
|
2036
|
+
if (response.circuit === 'oidc_domain_attestation') {
|
|
2037
|
+
const found = this.oidcRequestFor(response, options?.request);
|
|
2038
|
+
if ('error' in found)
|
|
2039
|
+
return { valid: false, error: found.error };
|
|
2040
|
+
request = found.request;
|
|
2041
|
+
}
|
|
2042
|
+
return verifyProofOffChain(response.circuit, response.proof, response.publicInputs, { ...options, request });
|
|
1866
2043
|
}
|
|
1867
2044
|
// ============ Utility Methods ============
|
|
1868
2045
|
/**
|
|
@@ -1883,8 +2060,17 @@ class ProofportSDK {
|
|
|
1883
2060
|
* ```
|
|
1884
2061
|
*/
|
|
1885
2062
|
getVerifierAddress(circuit) {
|
|
1886
|
-
|
|
1887
|
-
|
|
2063
|
+
return this.requireVerifier(circuit).address;
|
|
2064
|
+
}
|
|
2065
|
+
/** The configured or pinned verifier, or an error saying why there is none. */
|
|
2066
|
+
requireVerifier(circuit) {
|
|
2067
|
+
const target = this.verifierTarget(circuit);
|
|
2068
|
+
if (!target) {
|
|
2069
|
+
throw new Error(`No verifier configured for circuit '${circuit}'. Configure one in the SDK's verifiers option, or create the SDK with ProofportSDK.create() to use the pinned deployment.`);
|
|
2070
|
+
}
|
|
2071
|
+
if ('address' in target)
|
|
2072
|
+
return { address: target.address, chainId: target.chainId };
|
|
2073
|
+
return { address: core.getPinnedVerifier(circuit, target.chainId).address, chainId: target.chainId };
|
|
1888
2074
|
}
|
|
1889
2075
|
/**
|
|
1890
2076
|
* Gets the blockchain chain ID where the verifier contract is deployed.
|
|
@@ -1904,8 +2090,7 @@ class ProofportSDK {
|
|
|
1904
2090
|
* ```
|
|
1905
2091
|
*/
|
|
1906
2092
|
getVerifierChainId(circuit) {
|
|
1907
|
-
|
|
1908
|
-
return core.getVerifierChainId(circuit, customVerifier);
|
|
2093
|
+
return this.requireVerifier(circuit).chainId;
|
|
1909
2094
|
}
|
|
1910
2095
|
/**
|
|
1911
2096
|
* Gets metadata for a specific circuit type.
|
|
@@ -2052,17 +2237,20 @@ class ProofportSDK {
|
|
|
2052
2237
|
*/
|
|
2053
2238
|
static create(envOrConfig) {
|
|
2054
2239
|
if (typeof envOrConfig === 'undefined') {
|
|
2055
|
-
return
|
|
2240
|
+
return ProofportSDK.forEnvironment('production');
|
|
2056
2241
|
}
|
|
2057
2242
|
if (typeof envOrConfig === 'string') {
|
|
2058
|
-
|
|
2059
|
-
if (!relayUrl) {
|
|
2060
|
-
throw new Error(`Unknown environment: ${envOrConfig}. Use 'production', 'staging', or 'local'.`);
|
|
2061
|
-
}
|
|
2062
|
-
return new ProofportSDK({ relayUrl });
|
|
2243
|
+
return ProofportSDK.forEnvironment(envOrConfig);
|
|
2063
2244
|
}
|
|
2064
2245
|
return new ProofportSDK(envOrConfig);
|
|
2065
2246
|
}
|
|
2247
|
+
/** @internal An SDK on an environment preset's relay, verifying on that environment's chains. */
|
|
2248
|
+
static forEnvironment(env) {
|
|
2249
|
+
if (!Object.prototype.hasOwnProperty.call(RELAY_URLS, env)) {
|
|
2250
|
+
throw new Error(`Unknown environment: ${env}. Use 'production', 'staging', or 'local'.`);
|
|
2251
|
+
}
|
|
2252
|
+
return new ProofportSDK({ relayUrl: RELAY_URLS[env], environment: env });
|
|
2253
|
+
}
|
|
2066
2254
|
/**
|
|
2067
2255
|
* Detects if the code is running on a mobile device.
|
|
2068
2256
|
*
|
|
@@ -2196,7 +2384,10 @@ class ProofportSDK {
|
|
|
2196
2384
|
// calling createRelayRequest() for it with no signer got no local error and
|
|
2197
2385
|
// a relay 401 two round trips later.
|
|
2198
2386
|
static needsWalletSignature(circuit) {
|
|
2199
|
-
|
|
2387
|
+
if (!circuits.isCircuitId(circuit)) {
|
|
2388
|
+
throw new Error(`Unknown circuit '${circuit}'. Expected: ${circuits.ALL_CIRCUIT_IDS.join(', ')}`);
|
|
2389
|
+
}
|
|
2390
|
+
return circuits.CIRCUIT_NEEDS_WALLET_SIGNATURE[circuit];
|
|
2200
2391
|
}
|
|
2201
2392
|
async createRelayRequest(circuit, inputs, options = {}) {
|
|
2202
2393
|
if (!this.relayUrl) {
|
|
@@ -2287,7 +2478,9 @@ class ProofportSDK {
|
|
|
2287
2478
|
const error = await response.json().catch(() => ({ error: `HTTP ${response.status}` }));
|
|
2288
2479
|
throw new Error(error.error || `Relay request failed: HTTP ${response.status}`);
|
|
2289
2480
|
}
|
|
2290
|
-
|
|
2481
|
+
const created = await response.json();
|
|
2482
|
+
this.rememberRelayRequest(created.requestId, scope);
|
|
2483
|
+
return created;
|
|
2291
2484
|
}
|
|
2292
2485
|
/**
|
|
2293
2486
|
* Polls the relay for proof result status.
|
|
@@ -2570,6 +2763,23 @@ class ProofportSDK {
|
|
|
2570
2763
|
return core.extractDomainFromPublicInputs(publicInputs, circuit);
|
|
2571
2764
|
}
|
|
2572
2765
|
}
|
|
2766
|
+
/** Bound on {@link relayRequests}; a dApp that verifies later can pass the request explicitly. */
|
|
2767
|
+
ProofportSDK.MAX_REMEMBERED_RELAY_REQUESTS = 1000;
|
|
2768
|
+
/**
|
|
2769
|
+
* How each circuit's request is built and checked. Keyed by circuit id and
|
|
2770
|
+
* exhaustive over it, so a new circuit is a compile error here instead of
|
|
2771
|
+
* falling through to another circuit's builder.
|
|
2772
|
+
*/
|
|
2773
|
+
ProofportSDK.REQUEST_BUILDERS = {
|
|
2774
|
+
coinbase_attestation: 'scoped',
|
|
2775
|
+
coinbase_country_attestation: 'country',
|
|
2776
|
+
oidc_domain_attestation: 'scoped',
|
|
2777
|
+
giwa_attestation: 'scoped',
|
|
2778
|
+
dojang_playground: 'scoped',
|
|
2779
|
+
mdl_kr_ownership: 'mdl',
|
|
2780
|
+
mdl_kr_age: 'mdl',
|
|
2781
|
+
mdl_kr_region: 'mdl',
|
|
2782
|
+
};
|
|
2573
2783
|
|
|
2574
2784
|
Object.defineProperty(exports, "COINBASE_ATTESTATION_PUBLIC_INPUT_LAYOUT", {
|
|
2575
2785
|
enumerable: true,
|
|
@@ -2583,10 +2793,46 @@ Object.defineProperty(exports, "MDL_KR_PUBLIC_INPUT_LAYOUT", {
|
|
|
2583
2793
|
enumerable: true,
|
|
2584
2794
|
get: function () { return core.MDL_KR_PUBLIC_INPUT_LAYOUT; }
|
|
2585
2795
|
});
|
|
2796
|
+
Object.defineProperty(exports, "OIDC_ALLOWED_AUDIENCES", {
|
|
2797
|
+
enumerable: true,
|
|
2798
|
+
get: function () { return core.OIDC_ALLOWED_AUDIENCES; }
|
|
2799
|
+
});
|
|
2586
2800
|
Object.defineProperty(exports, "OIDC_DOMAIN_ATTESTATION_PUBLIC_INPUT_LAYOUT", {
|
|
2587
2801
|
enumerable: true,
|
|
2588
2802
|
get: function () { return core.OIDC_DOMAIN_ATTESTATION_PUBLIC_INPUT_LAYOUT; }
|
|
2589
2803
|
});
|
|
2804
|
+
Object.defineProperty(exports, "OIDC_NONCE_DOMAIN", {
|
|
2805
|
+
enumerable: true,
|
|
2806
|
+
get: function () { return core.OIDC_NONCE_DOMAIN; }
|
|
2807
|
+
});
|
|
2808
|
+
Object.defineProperty(exports, "OIDC_NOW_MAX_AGE_SECONDS", {
|
|
2809
|
+
enumerable: true,
|
|
2810
|
+
get: function () { return core.OIDC_NOW_MAX_AGE_SECONDS; }
|
|
2811
|
+
});
|
|
2812
|
+
Object.defineProperty(exports, "OIDC_NOW_MAX_FUTURE_SECONDS", {
|
|
2813
|
+
enumerable: true,
|
|
2814
|
+
get: function () { return core.OIDC_NOW_MAX_FUTURE_SECONDS; }
|
|
2815
|
+
});
|
|
2816
|
+
Object.defineProperty(exports, "OIDC_V1_PUBLIC_INPUT_COUNT", {
|
|
2817
|
+
enumerable: true,
|
|
2818
|
+
get: function () { return core.OIDC_V1_PUBLIC_INPUT_COUNT; }
|
|
2819
|
+
});
|
|
2820
|
+
Object.defineProperty(exports, "OIDC_V2_PUBLIC_INPUT_COUNT", {
|
|
2821
|
+
enumerable: true,
|
|
2822
|
+
get: function () { return core.OIDC_V2_PUBLIC_INPUT_COUNT; }
|
|
2823
|
+
});
|
|
2824
|
+
Object.defineProperty(exports, "PINNED_VERIFIERS", {
|
|
2825
|
+
enumerable: true,
|
|
2826
|
+
get: function () { return core.PINNED_VERIFIERS; }
|
|
2827
|
+
});
|
|
2828
|
+
Object.defineProperty(exports, "checkOidcPolicy", {
|
|
2829
|
+
enumerable: true,
|
|
2830
|
+
get: function () { return core.checkOidcPolicy; }
|
|
2831
|
+
});
|
|
2832
|
+
Object.defineProperty(exports, "deriveOidcNonceBinding", {
|
|
2833
|
+
enumerable: true,
|
|
2834
|
+
get: function () { return core.deriveOidcNonceBinding; }
|
|
2835
|
+
});
|
|
2590
2836
|
Object.defineProperty(exports, "extractDomainFromPublicInputs", {
|
|
2591
2837
|
enumerable: true,
|
|
2592
2838
|
get: function () { return core.extractDomainFromPublicInputs; }
|
|
@@ -2599,6 +2845,14 @@ Object.defineProperty(exports, "extractScopeFromPublicInputs", {
|
|
|
2599
2845
|
enumerable: true,
|
|
2600
2846
|
get: function () { return core.extractScopeFromPublicInputs; }
|
|
2601
2847
|
});
|
|
2848
|
+
Object.defineProperty(exports, "getPinnedVerifier", {
|
|
2849
|
+
enumerable: true,
|
|
2850
|
+
get: function () { return core.getPinnedVerifier; }
|
|
2851
|
+
});
|
|
2852
|
+
Object.defineProperty(exports, "oidcAudienceHash", {
|
|
2853
|
+
enumerable: true,
|
|
2854
|
+
get: function () { return core.oidcAudienceHash; }
|
|
2855
|
+
});
|
|
2602
2856
|
Object.defineProperty(exports, "ALL_CIRCUIT_IDS", {
|
|
2603
2857
|
enumerable: true,
|
|
2604
2858
|
get: function () { return circuits.ALL_CIRCUIT_IDS; }
|