@zkproofport-app/sdk 0.3.1 → 0.3.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 +93 -9
- package/dist/circuits.d.ts +39 -2
- package/dist/circuits.esm.js +47 -13
- package/dist/circuits.esm.js.map +1 -1
- package/dist/circuits.js +48 -12
- package/dist/circuits.js.map +1 -1
- package/dist/circuits.mjs +47 -13
- package/dist/circuits.mjs.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.esm.js +110 -35
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +111 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +110 -35
- package/dist/index.mjs.map +1 -1
- package/dist/typedAction.d.ts +5 -0
- package/dist/typedAction.esm.js +5 -0
- package/dist/typedAction.esm.js.map +1 -1
- package/dist/typedAction.js +5 -0
- package/dist/typedAction.js.map +1 -1
- package/dist/typedAction.mjs +5 -0
- package/dist/typedAction.mjs.map +1 -1
- package/dist/types.d.ts +24 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -96,16 +96,22 @@ const CIRCUIT_METADATA = {
|
|
|
96
96
|
},
|
|
97
97
|
// Planned circuit — the identifier is reserved and the circuit exists, but it
|
|
98
98
|
// is not officially supported yet. See CIRCUIT_SUPPORT_STATUS in ./circuits.
|
|
99
|
-
// Forked from coinbase_attestation
|
|
100
|
-
//
|
|
101
|
-
//
|
|
102
|
-
//
|
|
103
|
-
//
|
|
99
|
+
// Forked from coinbase_attestation, then given the EIP-712 pair and a
|
|
100
|
+
// branch: with an action the wallet signs the typed data and signal_hash is
|
|
101
|
+
// zero; without one it signs signal_hash and the pair is zero. Read off the
|
|
102
|
+
// compiled ABI (6 x [u8; 32] = 192): signal_hash 0-31, domain_separator
|
|
103
|
+
// 32-63, action_hash 64-95, signer_list_merkle_root 96-127, scope 128-159,
|
|
104
|
+
// nullifier 160-191 -- the same order as arc_eligibility.
|
|
105
|
+
//
|
|
106
|
+
// Unlike Arc, signal_hash is NOT part of this circuit's nullifier. That one
|
|
107
|
+
// derives its nullifier from a public input nobody signs and nothing
|
|
108
|
+
// constrains, so one wallet can mint as many nullifiers as it likes; here
|
|
109
|
+
// the secret is the address plus a constant compiled into the circuit.
|
|
104
110
|
giwa_attestation: {
|
|
105
111
|
name: 'GIWA Attestation',
|
|
106
|
-
description: 'Prove GIWA identity verification (planned — not officially supported yet)',
|
|
107
|
-
publicInputsCount:
|
|
108
|
-
publicInputNames: ['signal_hash', 'signer_list_merkle_root', 'scope', 'nullifier'],
|
|
112
|
+
description: 'Prove GIWA identity verification, optionally authorizing one EIP-712 action (planned — not officially supported yet)',
|
|
113
|
+
publicInputsCount: 192,
|
|
114
|
+
publicInputNames: ['signal_hash', 'domain_separator', 'action_hash', 'signer_list_merkle_root', 'scope', 'nullifier'],
|
|
109
115
|
},
|
|
110
116
|
// Korea Mobile ID (mDL) circuits. Planned — not officially supported yet.
|
|
111
117
|
// Counts are byte-flattened field totals from the compiled circuit ABIs:
|
|
@@ -384,7 +390,7 @@ const CIRCUIT_IDS = Object.freeze({
|
|
|
384
390
|
COINBASE_COUNTRY_ATTESTATION: 'coinbase_country_attestation',
|
|
385
391
|
/** OIDC email-domain attestation. Officially supported. */
|
|
386
392
|
OIDC_DOMAIN_ATTESTATION: 'oidc_domain_attestation',
|
|
387
|
-
/** Arc eligibility:
|
|
393
|
+
/** Arc eligibility: exact EIP-712 action authorization. Experimental on Arc Testnet. */
|
|
388
394
|
ARC_ELIGIBILITY: 'arc_eligibility',
|
|
389
395
|
/** GIWA attestation. Planned — not officially supported yet. */
|
|
390
396
|
GIWA_ATTESTATION: 'giwa_attestation',
|
|
@@ -415,7 +421,11 @@ const CIRCUIT_SUPPORT_STATUS = Object.freeze({
|
|
|
415
421
|
coinbase_country_attestation: 'supported',
|
|
416
422
|
oidc_domain_attestation: 'supported',
|
|
417
423
|
arc_eligibility: 'experimental',
|
|
418
|
-
|
|
424
|
+
// Experimental, not planned: the circuit is built, its verifier is
|
|
425
|
+
// deployed on GIWA Sepolia and the demo requests it. What keeps it out of
|
|
426
|
+
// 'supported' is that it is testnet-only, so the app offers it behind
|
|
427
|
+
// Developer Mode and reads its files from main rather than a release tag.
|
|
428
|
+
giwa_attestation: 'experimental',
|
|
419
429
|
mdl_kr_ownership: 'planned',
|
|
420
430
|
mdl_kr_age: 'planned',
|
|
421
431
|
mdl_kr_region: 'planned',
|
|
@@ -527,18 +537,44 @@ function getCircuitSupportStatus(circuit) {
|
|
|
527
537
|
}
|
|
528
538
|
return CIRCUIT_SUPPORT_STATUS[circuit];
|
|
529
539
|
}
|
|
530
|
-
|
|
531
|
-
|
|
540
|
+
const CIRCUIT_ACTION_BINDING = {
|
|
541
|
+
coinbase_attestation: 'none',
|
|
542
|
+
coinbase_country_attestation: 'none',
|
|
543
|
+
// The signature lives inside the identity token; no wallet, no action.
|
|
544
|
+
oidc_domain_attestation: 'none',
|
|
545
|
+
// Both branch in-circuit: with an action the wallet signs the typed data,
|
|
546
|
+
// without one it personal_signs the request's signal hash. Arc read
|
|
547
|
+
// 'required' until 2026-09-22 because its circuit had no second path -- a
|
|
548
|
+
// request without an action built a vector 64 bytes short and died inside
|
|
549
|
+
// the prover. The circuit gained the branch; the table follows it.
|
|
550
|
+
arc_eligibility: 'optional',
|
|
551
|
+
giwa_attestation: 'optional',
|
|
552
|
+
mdl_kr_ownership: 'none',
|
|
553
|
+
mdl_kr_age: 'none',
|
|
554
|
+
mdl_kr_region: 'none',
|
|
555
|
+
};
|
|
556
|
+
/*
|
|
557
|
+
* The union is declared above rather than derived from the table's values.
|
|
532
558
|
*
|
|
533
|
-
*
|
|
534
|
-
*
|
|
535
|
-
*
|
|
536
|
-
*
|
|
537
|
-
*
|
|
559
|
+
* Deriving it narrowed the type to whatever the table happens to hold today --
|
|
560
|
+
* 'none' | 'optional' -- and TypeScript then called every `=== 'required'`
|
|
561
|
+
* check impossible. The publish typecheck caught it; `rollup` and `vitest` did
|
|
562
|
+
* not. 'required' is a state a circuit can legitimately be in (an EIP-712 path
|
|
563
|
+
* and nothing else), so the union says so and the table is checked against it.
|
|
564
|
+
*/
|
|
565
|
+
/**
|
|
566
|
+
* How this circuit treats an action, or an error naming the id that is not one.
|
|
538
567
|
*
|
|
539
|
-
*
|
|
540
|
-
*
|
|
568
|
+
* No default: a circuit nobody has classified must not inherit 'none', which
|
|
569
|
+
* would silently drop an action a dapp meant to bind.
|
|
541
570
|
*/
|
|
571
|
+
function circuitActionBinding(circuit) {
|
|
572
|
+
const binding = CIRCUIT_ACTION_BINDING[circuit];
|
|
573
|
+
if (!binding) {
|
|
574
|
+
throw new Error(`Unknown circuit '${circuit}'. Expected: ${ALL_CIRCUIT_IDS.join(', ')}`);
|
|
575
|
+
}
|
|
576
|
+
return binding;
|
|
577
|
+
}
|
|
542
578
|
const CIRCUIT_NEEDS_WALLET_SIGNATURE = {
|
|
543
579
|
coinbase_attestation: true,
|
|
544
580
|
coinbase_country_attestation: true,
|
|
@@ -551,13 +587,22 @@ const CIRCUIT_NEEDS_WALLET_SIGNATURE = {
|
|
|
551
587
|
mdl_kr_ownership: false,
|
|
552
588
|
mdl_kr_age: false,
|
|
553
589
|
mdl_kr_region: false,
|
|
554
|
-
|
|
590
|
+
// A GIWA-attested wallet signing an EIP-712 action, the same shape as Arc.
|
|
591
|
+
// This read `false` while the circuit had always verified a wallet signature
|
|
592
|
+
// -- it sat under the Web2 comment above and was never revisited. A request
|
|
593
|
+
// for it would have reached the relay with no signer.
|
|
594
|
+
giwa_attestation: true,
|
|
555
595
|
};
|
|
556
596
|
|
|
557
597
|
const ADDRESS = /^0x[0-9a-fA-F]{40}$/;
|
|
558
598
|
/**
|
|
559
599
|
* The reason the value is not a usable action, or `null` when it is one.
|
|
560
600
|
*
|
|
601
|
+
* Structural validation only, not application authorization policy. Consumers
|
|
602
|
+
* (e.g. EligibilityGate) must independently enforce the expected chain, verifying
|
|
603
|
+
* contract, actor, action parameters, nonce and deadline as applicable.
|
|
604
|
+
* EIP-712 signs only fields declared in types, not extra message properties.
|
|
605
|
+
*
|
|
561
606
|
* A string rather than a boolean because every caller shows it to somebody —
|
|
562
607
|
* a dapp developer reading a validation error, or a person looking at the
|
|
563
608
|
* mobile app's demo screen.
|
|
@@ -1181,9 +1226,26 @@ function validateProofRequest(request) {
|
|
|
1181
1226
|
if (inputs.userAddress && !/^0x[a-fA-F0-9]{40}$/.test(inputs.userAddress)) {
|
|
1182
1227
|
return { valid: false, error: 'Invalid userAddress format' };
|
|
1183
1228
|
}
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1229
|
+
}
|
|
1230
|
+
// The action, decided by the circuit's own entry rather than by naming a
|
|
1231
|
+
// circuit here. This used to be part of the arc_eligibility branch above,
|
|
1232
|
+
// which is why a second action-capable circuit had nowhere to be checked.
|
|
1233
|
+
{
|
|
1234
|
+
const action = request.inputs?.action;
|
|
1235
|
+
const binding = circuitActionBinding(request.circuit);
|
|
1236
|
+
if (binding === 'none') {
|
|
1237
|
+
if (action !== undefined) {
|
|
1238
|
+
return {
|
|
1239
|
+
valid: false,
|
|
1240
|
+
error: `${request.circuit} has no action inputs, so an action sent with it would not be proved. Refusing rather than dropping it.`,
|
|
1241
|
+
};
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
else if (binding === 'required' || action !== undefined) {
|
|
1245
|
+
const actionError = validateTypedAction(action);
|
|
1246
|
+
if (actionError) {
|
|
1247
|
+
return { valid: false, error: actionError };
|
|
1248
|
+
}
|
|
1187
1249
|
}
|
|
1188
1250
|
}
|
|
1189
1251
|
// Check expiry
|
|
@@ -1617,8 +1679,10 @@ function getVerifierChainId(circuit, customVerifier) {
|
|
|
1617
1679
|
const PUBLIC_INPUT_OFFSETS = Object.freeze({
|
|
1618
1680
|
// signal_hash, signer_list_merkle_root, scope, nullifier
|
|
1619
1681
|
coinbase_attestation: { scope: [64, 95], nullifier: [96, 127] },
|
|
1620
|
-
//
|
|
1621
|
-
|
|
1682
|
+
// No longer Coinbase's layout. The GIWA circuit gained the EIP-712 pair, so
|
|
1683
|
+
// it reads like Arc: signal_hash, domain_separator, action_hash, merkle
|
|
1684
|
+
// root, then scope and nullifier 64 bytes further along than Coinbase.
|
|
1685
|
+
giwa_attestation: { scope: [128, 159], nullifier: [160, 191] },
|
|
1622
1686
|
// country_list, country_list_length and is_included sit before scope.
|
|
1623
1687
|
coinbase_country_attestation: { scope: [86, 117], nullifier: [118, 149] },
|
|
1624
1688
|
// pubkey_modulus_limbs and the bounded domain sit before scope.
|
|
@@ -3027,15 +3091,26 @@ class ProofportSDK {
|
|
|
3027
3091
|
throw new Error(`${mdlError} (circuit: ${circuit})`);
|
|
3028
3092
|
}
|
|
3029
3093
|
}
|
|
3030
|
-
//
|
|
3031
|
-
//
|
|
3032
|
-
//
|
|
3033
|
-
//
|
|
3034
|
-
//
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3094
|
+
// The action, per the circuit's entry in CIRCUIT_ACTION_BINDING. Checked
|
|
3095
|
+
// here, before a challenge is burned, because the alternative is a refusal
|
|
3096
|
+
// from inside the mobile app -- a screen the dapp developer never sees,
|
|
3097
|
+
// reached after the person has already scanned a QR code.
|
|
3098
|
+
//
|
|
3099
|
+
// This named arc_eligibility directly until giwa_attestation became the
|
|
3100
|
+
// second circuit that can carry an action; the id belongs in the table,
|
|
3101
|
+
// not in the check.
|
|
3102
|
+
{
|
|
3103
|
+
const action = inputs.action;
|
|
3104
|
+
const binding = circuitActionBinding(circuit);
|
|
3105
|
+
if (binding === 'none' && action !== undefined) {
|
|
3106
|
+
throw new Error(`${circuit} has no action inputs, so an action sent with it would not be proved. ` +
|
|
3107
|
+
'Remove it, or use a circuit that binds one.');
|
|
3108
|
+
}
|
|
3109
|
+
if (binding === 'required' || (binding === 'optional' && action !== undefined)) {
|
|
3110
|
+
const actionError = validateTypedAction(action);
|
|
3111
|
+
if (actionError) {
|
|
3112
|
+
throw new Error(`${actionError} (circuit: ${circuit})`);
|
|
3113
|
+
}
|
|
3039
3114
|
}
|
|
3040
3115
|
}
|
|
3041
3116
|
// Return target: validated before we burn a challenge, so a typo surfaces
|
|
@@ -3364,6 +3439,7 @@ class ProofportSDK {
|
|
|
3364
3439
|
}
|
|
3365
3440
|
|
|
3366
3441
|
exports.ALL_CIRCUIT_IDS = ALL_CIRCUIT_IDS;
|
|
3442
|
+
exports.CIRCUIT_ACTION_BINDING = CIRCUIT_ACTION_BINDING;
|
|
3367
3443
|
exports.CIRCUIT_IDS = CIRCUIT_IDS;
|
|
3368
3444
|
exports.CIRCUIT_SUPPORT_STATUS = CIRCUIT_SUPPORT_STATUS;
|
|
3369
3445
|
exports.CIRCUIT_VK_PATHS = CIRCUIT_VK_PATHS;
|
|
@@ -3375,6 +3451,7 @@ exports.OIDC_DOMAIN_ATTESTATION_PUBLIC_INPUT_LAYOUT = OIDC_DOMAIN_ATTESTATION_PU
|
|
|
3375
3451
|
exports.PLANNED_CIRCUIT_IDS = PLANNED_CIRCUIT_IDS;
|
|
3376
3452
|
exports.ProofportSDK = ProofportSDK;
|
|
3377
3453
|
exports.SUPPORTED_CIRCUIT_IDS = SUPPORTED_CIRCUIT_IDS;
|
|
3454
|
+
exports.circuitActionBinding = circuitActionBinding;
|
|
3378
3455
|
exports.default = ProofportSDK;
|
|
3379
3456
|
exports.extractDomainFromPublicInputs = extractDomainFromPublicInputs;
|
|
3380
3457
|
exports.extractNullifierFromPublicInputs = extractNullifierFromPublicInputs;
|