@zkproofport-app/sdk 0.2.5 → 0.2.7

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/dist/index.js CHANGED
@@ -75,8 +75,8 @@ const CIRCUIT_METADATA = {
75
75
  oidc_domain_attestation: {
76
76
  name: 'OIDC Domain',
77
77
  description: 'Prove email domain affiliation via OIDC JWT',
78
- publicInputsCount: 420,
79
- publicInputNames: ['pubkey_modulus_limbs', 'domain', 'scope', 'nullifier'],
78
+ publicInputsCount: 148,
79
+ publicInputNames: ['pubkey_modulus_limbs', 'domain', 'scope', 'nullifier', 'provider'],
80
80
  },
81
81
  };
82
82
  /**
@@ -210,14 +210,15 @@ const COINBASE_COUNTRY_PUBLIC_INPUT_LAYOUT = {
210
210
  NULLIFIER_END: 149,
211
211
  };
212
212
  /**
213
- * OIDC Domain Attestation circuit public input layout (byte offsets).
214
- * Defines the byte positions of each field in the flattened public inputs array.
213
+ * OIDC Domain Attestation circuit public input layout (field offsets).
214
+ * Defines the field positions in the flattened public inputs array (148 fields total).
215
215
  *
216
- * Public inputs are packed as individual field elements (one byte per element):
217
- * - pubkey_modulus_limbs: 18 x u128 = 18 x 16 bytes = 288 bytes → fields 0–287
218
- * - domain (BoundedVec<u8, 64>): 4-byte length (u32) + 64-byte storage = 68 fields → fields 288355
219
- * - scope: 32 bytes → fields 356387
220
- * - nullifier: 32 bytes → fields 388419
216
+ * Circuit public inputs (from main.nr):
217
+ * - pubkey_modulus_limbs: pub [u128; 18] 18 fields (0–17)
218
+ * - domain: pub BoundedVec<u8, 64> 1 len + 64 storage = 65 fields (1882)
219
+ * - scope: pub [u8; 32]32 fields (83114)
220
+ * - nullifier: pub [u8; 32]32 fields (115146)
221
+ * - provider: pub u8 → 1 field (147)
221
222
  *
222
223
  * @example
223
224
  * ```typescript
@@ -229,13 +230,19 @@ const COINBASE_COUNTRY_PUBLIC_INPUT_LAYOUT = {
229
230
  */
230
231
  const OIDC_DOMAIN_ATTESTATION_PUBLIC_INPUT_LAYOUT = {
231
232
  PUBKEY_MODULUS_START: 0,
232
- PUBKEY_MODULUS_END: 287,
233
- DOMAIN_START: 288,
234
- DOMAIN_END: 355,
235
- SCOPE_START: 356,
236
- SCOPE_END: 387,
237
- NULLIFIER_START: 388,
238
- NULLIFIER_END: 419,
233
+ PUBKEY_MODULUS_END: 17,
234
+ DOMAIN_STORAGE_START: 18,
235
+ DOMAIN_STORAGE_END: 81,
236
+ DOMAIN_LEN: 82,
237
+ SCOPE_START: 83,
238
+ SCOPE_END: 114,
239
+ NULLIFIER_START: 115,
240
+ NULLIFIER_END: 146,
241
+ PROVIDER: 147,
242
+ /** @deprecated Use DOMAIN_STORAGE_START */
243
+ DOMAIN_START: 18,
244
+ /** @deprecated Use DOMAIN_LEN */
245
+ DOMAIN_END: 82,
239
246
  };
240
247
 
241
248
  /**
@@ -966,8 +973,8 @@ function extractScopeFromPublicInputs(publicInputsHex, circuit) {
966
973
  end = 117;
967
974
  }
968
975
  else if (circuit === 'oidc_domain_attestation') {
969
- start = 356;
970
- end = 387;
976
+ start = 83;
977
+ end = 114;
971
978
  }
972
979
  else {
973
980
  start = 64;
@@ -1003,8 +1010,8 @@ function extractNullifierFromPublicInputs(publicInputsHex, circuit) {
1003
1010
  end = 149;
1004
1011
  }
1005
1012
  else if (circuit === 'oidc_domain_attestation') {
1006
- start = 388;
1007
- end = 419;
1013
+ start = 115;
1014
+ end = 146;
1008
1015
  }
1009
1016
  else {
1010
1017
  start = 96;
@@ -1015,6 +1022,38 @@ function extractNullifierFromPublicInputs(publicInputsHex, circuit) {
1015
1022
  const nullifierFields = publicInputsHex.slice(start, end + 1);
1016
1023
  return reconstructBytes32FromFields(nullifierFields);
1017
1024
  }
1025
+ /**
1026
+ * Extract domain string from OIDC Domain Attestation public inputs.
1027
+ *
1028
+ * The domain is stored as a Noir BoundedVec<u8, 64>, which serializes as
1029
+ * [storage[0..64], len]. Each storage element is a u8 value in a field element.
1030
+ *
1031
+ * @param publicInputsHex - Array of public input hex strings
1032
+ * @param circuit - Circuit identifier (must be 'oidc_domain_attestation')
1033
+ * @returns Domain as ASCII string, or null if circuit doesn't match or inputs are insufficient
1034
+ *
1035
+ * @example
1036
+ * ```typescript
1037
+ * const domain = extractDomainFromPublicInputs(publicInputs, 'oidc_domain_attestation');
1038
+ * console.log(domain); // 'example.com'
1039
+ * ```
1040
+ */
1041
+ function extractDomainFromPublicInputs(publicInputsHex, circuit) {
1042
+ if (circuit !== 'oidc_domain_attestation')
1043
+ return null;
1044
+ const layout = OIDC_DOMAIN_ATTESTATION_PUBLIC_INPUT_LAYOUT;
1045
+ if (publicInputsHex.length <= layout.DOMAIN_LEN)
1046
+ return null;
1047
+ const len = Number(BigInt(publicInputsHex[layout.DOMAIN_LEN]) & 0xffn);
1048
+ if (len === 0 || len > 64)
1049
+ return null;
1050
+ const storageFields = publicInputsHex.slice(layout.DOMAIN_STORAGE_START, layout.DOMAIN_STORAGE_START + len);
1051
+ const chars = storageFields.map(f => {
1052
+ const byte = Number(BigInt(f) & 0xffn);
1053
+ return String.fromCharCode(byte);
1054
+ });
1055
+ return chars.join('');
1056
+ }
1018
1057
  /** @internal Reconstruct a bytes32 value from 32 individual field elements */
1019
1058
  function reconstructBytes32FromFields(fields) {
1020
1059
  if (fields.length !== 32) {
@@ -2192,6 +2231,27 @@ class ProofportSDK {
2192
2231
  extractNullifier(publicInputs, circuit) {
2193
2232
  return extractNullifierFromPublicInputs(publicInputs, circuit);
2194
2233
  }
2234
+ /**
2235
+ * Extracts the domain string from OIDC Domain Attestation proof public inputs.
2236
+ *
2237
+ * Only works with 'oidc_domain_attestation' circuit. Returns null for other circuits.
2238
+ *
2239
+ * @param publicInputs - Array of hex-encoded field elements from proof result
2240
+ * @param circuit - Circuit type that produced the public inputs
2241
+ * @returns Domain as ASCII string (e.g., 'example.com'), or null if not applicable
2242
+ *
2243
+ * @example
2244
+ * ```typescript
2245
+ * const result = await sdk.waitForProof(relay.requestId);
2246
+ * if (result.status === 'completed') {
2247
+ * const domain = sdk.extractDomain(result.publicInputs, result.circuit);
2248
+ * console.log('Domain:', domain); // 'example.com'
2249
+ * }
2250
+ * ```
2251
+ */
2252
+ extractDomain(publicInputs, circuit) {
2253
+ return extractDomainFromPublicInputs(publicInputs, circuit);
2254
+ }
2195
2255
  }
2196
2256
  /**
2197
2257
  * Creates a proof request through the relay server.
@@ -2235,6 +2295,7 @@ exports.COINBASE_COUNTRY_PUBLIC_INPUT_LAYOUT = COINBASE_COUNTRY_PUBLIC_INPUT_LAY
2235
2295
  exports.OIDC_DOMAIN_ATTESTATION_PUBLIC_INPUT_LAYOUT = OIDC_DOMAIN_ATTESTATION_PUBLIC_INPUT_LAYOUT;
2236
2296
  exports.ProofportSDK = ProofportSDK;
2237
2297
  exports.default = ProofportSDK;
2298
+ exports.extractDomainFromPublicInputs = extractDomainFromPublicInputs;
2238
2299
  exports.extractNullifierFromPublicInputs = extractNullifierFromPublicInputs;
2239
2300
  exports.extractScopeFromPublicInputs = extractScopeFromPublicInputs;
2240
2301
  //# sourceMappingURL=index.js.map