Skip to content

Commit 46a4c0c

Browse files
authored
Merge pull request #66 from reclaimprotocol/fix/verify_proof
fix: canonicalize context JSON before computing claim identifier
2 parents 945c126 + d3a2822 commit 46a4c0c

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@reclaimprotocol/js-sdk",
3-
"version": "4.6.3",
3+
"version": "4.6.4",
44
"description": "Designed to request proofs from the Reclaim protocol and manage the flow of claims and witness interactions.",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/witness.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ethers } from 'ethers';
22
import type { WitnessData } from './utils/interfaces';
33
import type { ClaimID, ClaimInfo, CompleteClaimData } from './utils/types';
4+
import { canonicalStringify } from './utils/strings';
45

56
type BeaconState = {
67
witnesses: WitnessData[];
@@ -42,8 +43,20 @@ export function fetchWitnessListForClaim(
4243
return selectedWitnesses;
4344
}
4445

46+
4547
export function getIdentifierFromClaimInfo(info: ClaimInfo): ClaimID {
46-
const str: string = `${info.provider}\n${info.parameters}\n${info.context || ''}`;
48+
// re-canonicalize context if it's not empty
49+
let canonicalContext = info.context || '';
50+
if (canonicalContext.length > 0) {
51+
try {
52+
const ctx = JSON.parse(canonicalContext);
53+
canonicalContext = canonicalStringify(ctx);
54+
} catch (e) {
55+
throw new Error('unable to parse non-empty context. Must be JSON');
56+
}
57+
}
58+
59+
const str = `${info.provider}\n${info.parameters}\n${canonicalContext}`;
4760
return ethers.keccak256(strToUint8Array(str)).toLowerCase();
4861
}
4962

0 commit comments

Comments
 (0)