@zkproofport-app/sdk 0.2.1 → 0.2.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 +35 -0
- package/dist/ProofportSDK.d.ts +22 -0
- package/dist/constants.d.ts +4 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.esm.js +121 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +124 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +121 -1
- package/dist/index.mjs.map +1 -1
- package/dist/verifier.d.ts +19 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -140,6 +140,69 @@ const DEFAULT_REQUEST_EXPIRY_MS = 10 * 60 * 1000;
|
|
|
140
140
|
* ```
|
|
141
141
|
*/
|
|
142
142
|
const MAX_QR_DATA_SIZE = 2953; // Version 40 with L error correction
|
|
143
|
+
/**
|
|
144
|
+
* Coinbase Attestation circuit public input layout (byte offsets).
|
|
145
|
+
* Defines the byte positions of each field in the flattened public inputs array.
|
|
146
|
+
*
|
|
147
|
+
* Public inputs are packed as bytes32 values:
|
|
148
|
+
* - signal_hash: bytes 0-31
|
|
149
|
+
* - merkle_root: bytes 32-63
|
|
150
|
+
* - scope: bytes 64-95
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* const publicInputs = response.publicInputs;
|
|
155
|
+
* const signalHash = publicInputs.slice(
|
|
156
|
+
* COINBASE_ATTESTATION_PUBLIC_INPUT_LAYOUT.SIGNAL_HASH_START,
|
|
157
|
+
* COINBASE_ATTESTATION_PUBLIC_INPUT_LAYOUT.SIGNAL_HASH_END + 1
|
|
158
|
+
* );
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
const COINBASE_ATTESTATION_PUBLIC_INPUT_LAYOUT = {
|
|
162
|
+
SIGNAL_HASH_START: 0,
|
|
163
|
+
SIGNAL_HASH_END: 31,
|
|
164
|
+
MERKLE_ROOT_START: 32,
|
|
165
|
+
MERKLE_ROOT_END: 63,
|
|
166
|
+
SCOPE_START: 64,
|
|
167
|
+
SCOPE_END: 95,
|
|
168
|
+
NULLIFIER_START: 96,
|
|
169
|
+
NULLIFIER_END: 127,
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* Coinbase Country Attestation circuit public input layout (byte offsets).
|
|
173
|
+
* Defines the byte positions of each field in the flattened public inputs array.
|
|
174
|
+
*
|
|
175
|
+
* Public inputs are packed as bytes32 values:
|
|
176
|
+
* - signal_hash: bytes 0-31
|
|
177
|
+
* - merkle_root: bytes 32-63
|
|
178
|
+
* - country_list: bytes 64-83 (20 bytes for 10 countries)
|
|
179
|
+
* - country_list_length: byte 84
|
|
180
|
+
* - is_included: byte 85
|
|
181
|
+
* - scope: bytes 86-117
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```typescript
|
|
185
|
+
* const publicInputs = response.publicInputs;
|
|
186
|
+
* const countryList = publicInputs.slice(
|
|
187
|
+
* COINBASE_COUNTRY_PUBLIC_INPUT_LAYOUT.COUNTRY_LIST_START,
|
|
188
|
+
* COINBASE_COUNTRY_PUBLIC_INPUT_LAYOUT.COUNTRY_LIST_END + 1
|
|
189
|
+
* );
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
const COINBASE_COUNTRY_PUBLIC_INPUT_LAYOUT = {
|
|
193
|
+
SIGNAL_HASH_START: 0,
|
|
194
|
+
SIGNAL_HASH_END: 31,
|
|
195
|
+
MERKLE_ROOT_START: 32,
|
|
196
|
+
MERKLE_ROOT_END: 63,
|
|
197
|
+
COUNTRY_LIST_START: 64,
|
|
198
|
+
COUNTRY_LIST_END: 83,
|
|
199
|
+
COUNTRY_LIST_LENGTH: 84,
|
|
200
|
+
IS_INCLUDED: 85,
|
|
201
|
+
SCOPE_START: 86,
|
|
202
|
+
SCOPE_END: 117,
|
|
203
|
+
NULLIFIER_START: 118,
|
|
204
|
+
NULLIFIER_END: 149,
|
|
205
|
+
};
|
|
143
206
|
|
|
144
207
|
/**
|
|
145
208
|
* Deep Link utilities for ZKProofport SDK
|
|
@@ -865,6 +928,39 @@ function extractScopeFromPublicInputs(publicInputsHex, circuit) {
|
|
|
865
928
|
const scopeFields = publicInputsHex.slice(start, end + 1);
|
|
866
929
|
return reconstructBytes32FromFields(scopeFields);
|
|
867
930
|
}
|
|
931
|
+
/**
|
|
932
|
+
* Extracts the nullifier (bytes32) from public inputs based on circuit type.
|
|
933
|
+
*
|
|
934
|
+
* The nullifier is a unique, deterministic hash derived from the user's attestation
|
|
935
|
+
* and scope. It serves as a privacy-preserving user identifier — the same user
|
|
936
|
+
* with the same scope always produces the same nullifier, enabling duplicate
|
|
937
|
+
* detection without revealing the wallet address.
|
|
938
|
+
*
|
|
939
|
+
* @param publicInputsHex - Array of hex-encoded field elements
|
|
940
|
+
* @param circuit - Circuit type (defaults to coinbase_attestation)
|
|
941
|
+
* @returns Nullifier as hex string (bytes32), or null if publicInputs too short
|
|
942
|
+
*
|
|
943
|
+
* @example
|
|
944
|
+
* ```typescript
|
|
945
|
+
* const nullifier = extractNullifierFromPublicInputs(publicInputs, 'coinbase_attestation');
|
|
946
|
+
* console.log(nullifier); // '0xabc123...'
|
|
947
|
+
* ```
|
|
948
|
+
*/
|
|
949
|
+
function extractNullifierFromPublicInputs(publicInputsHex, circuit) {
|
|
950
|
+
let start, end;
|
|
951
|
+
if (circuit === 'coinbase_country_attestation') {
|
|
952
|
+
start = 118;
|
|
953
|
+
end = 149;
|
|
954
|
+
}
|
|
955
|
+
else {
|
|
956
|
+
start = 96;
|
|
957
|
+
end = 127;
|
|
958
|
+
}
|
|
959
|
+
if (publicInputsHex.length <= end)
|
|
960
|
+
return null;
|
|
961
|
+
const nullifierFields = publicInputsHex.slice(start, end + 1);
|
|
962
|
+
return reconstructBytes32FromFields(nullifierFields);
|
|
963
|
+
}
|
|
868
964
|
/** @internal Reconstruct a bytes32 value from 32 individual field elements */
|
|
869
965
|
function reconstructBytes32FromFields(fields) {
|
|
870
966
|
if (fields.length !== 32) {
|
|
@@ -2045,8 +2141,36 @@ class ProofportSDK {
|
|
|
2045
2141
|
extractScope(publicInputs, circuit) {
|
|
2046
2142
|
return extractScopeFromPublicInputs(publicInputs, circuit);
|
|
2047
2143
|
}
|
|
2144
|
+
/**
|
|
2145
|
+
* Extracts the nullifier (bytes32) from proof public inputs.
|
|
2146
|
+
*
|
|
2147
|
+
* The nullifier is a unique, deterministic hash derived from the user's attestation
|
|
2148
|
+
* and scope. It serves as a privacy-preserving user identifier — the same user
|
|
2149
|
+
* with the same scope always produces the same nullifier, enabling duplicate
|
|
2150
|
+
* detection without revealing the wallet address.
|
|
2151
|
+
*
|
|
2152
|
+
* @param publicInputs - Array of hex-encoded field elements from proof result
|
|
2153
|
+
* @param circuit - Circuit type that produced the public inputs
|
|
2154
|
+
* @returns Nullifier as hex string (bytes32), or null if publicInputs too short
|
|
2155
|
+
*
|
|
2156
|
+
* @example
|
|
2157
|
+
* ```typescript
|
|
2158
|
+
* const result = await sdk.waitForProof(relay.requestId);
|
|
2159
|
+
* if (result.status === 'completed') {
|
|
2160
|
+
* const nullifier = sdk.extractNullifier(result.publicInputs, result.circuit);
|
|
2161
|
+
* console.log('Nullifier:', nullifier); // '0xabc123...'
|
|
2162
|
+
* }
|
|
2163
|
+
* ```
|
|
2164
|
+
*/
|
|
2165
|
+
extractNullifier(publicInputs, circuit) {
|
|
2166
|
+
return extractNullifierFromPublicInputs(publicInputs, circuit);
|
|
2167
|
+
}
|
|
2048
2168
|
}
|
|
2049
2169
|
|
|
2170
|
+
exports.COINBASE_ATTESTATION_PUBLIC_INPUT_LAYOUT = COINBASE_ATTESTATION_PUBLIC_INPUT_LAYOUT;
|
|
2171
|
+
exports.COINBASE_COUNTRY_PUBLIC_INPUT_LAYOUT = COINBASE_COUNTRY_PUBLIC_INPUT_LAYOUT;
|
|
2050
2172
|
exports.ProofportSDK = ProofportSDK;
|
|
2051
2173
|
exports.default = ProofportSDK;
|
|
2174
|
+
exports.extractNullifierFromPublicInputs = extractNullifierFromPublicInputs;
|
|
2175
|
+
exports.extractScopeFromPublicInputs = extractScopeFromPublicInputs;
|
|
2052
2176
|
//# sourceMappingURL=index.js.map
|