Skip to content

Commit

Permalink
v107
Browse files Browse the repository at this point in the history
  • Loading branch information
trevormil committed Jan 24, 2024
1 parent b235400 commit 234df16
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "blockin",
"version": "1.2.106",
"version": "1.2.107",
"description": "",
"files": [
"dist"
Expand Down
9 changes: 5 additions & 4 deletions src/types/verify.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ export function convertAssetConditionGroup<T extends NumberType, U extends Numbe

if (andItem['$and'] !== undefined) {
return {
$and: andItem.$and.map(group => convertAssetConditionGroup(group, convertFunction))
$and: andItem.$and.map(group => convertAssetConditionGroup(group, convertFunction, populateDefaults))
}
} else if (orItem['$or'] !== undefined) {
return {
$or: orItem.$or.map(group => convertAssetConditionGroup(group, convertFunction))
$or: orItem.$or.map(group => convertAssetConditionGroup(group, convertFunction, populateDefaults))
}
} else {
return {
Expand Down Expand Up @@ -104,8 +104,9 @@ export function convertAssetConditionGroup<T extends NumberType, U extends Numbe
}),

options: ownershipRequirements.options ? {
numMatchesForVerification: ownershipRequirements.options.numMatchesForVerification ? convertFunction(ownershipRequirements.options.numMatchesForVerification) :
populateDefaults ? 0 as U : undefined
numMatchesForVerification:
ownershipRequirements.options.numMatchesForVerification ? convertFunction(ownershipRequirements.options.numMatchesForVerification) :
populateDefaults ? 0 as U : undefined
} : populateDefaults ? {
numMatchesForVerification: 0 as U
} : undefined
Expand Down
6 changes: 2 additions & 4 deletions src/ui/SignInModal/SignInModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -354,16 +354,14 @@ const SignInModal: React.FC<SignInModalProps<NumberType>> = ({

{displayedAssetGroups.map(elem => {

const ownershipString = generateAssetConditionGroupString(elem.assetConditionGroup, 0, 1, 1);
const ownershipString = generateAssetConditionGroupString(elem.assetConditionGroup, 0, 1, '')


const lines = ownershipString.split('\n');
let currChain = 'Ethereum';
let currCollectionId: string | NumberType = '';
const convertedLines: ReactNode[] = [];
const chains: string[] = [];
console.log(elem.assetConditionGroup);
console.log(ownershipString);

for (const line of lines) {
const trimmedLine = line.trim();
Expand Down
18 changes: 8 additions & 10 deletions src/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export async function verifyChallenge<T extends NumberType>(

const toSkipSignatureVerification = options?.skipSignatureVerification ?? false;
if (!toSkipSignatureVerification) {
if (!chainDriver) throw `ChainDriver is required to verify assets`;
if (!chainDriver) throw `ChainDriver is required to verify signatures`;
await verifyChallengeSignature(chainDriver, message, signature)
}

Expand Down Expand Up @@ -530,24 +530,22 @@ function validateAssetConditionGroup<T extends NumberType>(assetConditionGroup:
}
}

export function generateAssetConditionGroupString<T extends NumberType>(assetConditionGroup: AssetConditionGroup<T>, depth: number = 0, bulletNumber: number, parentBullet: number): string {
export function generateAssetConditionGroupString<T extends NumberType>(assetConditionGroup: AssetConditionGroup<T>, depth: number = 0, bulletNumber: number, parentBullet: string): string {
let message = "";
const andItem = assetConditionGroup as AndGroup<T>;
const orItem = assetConditionGroup as OrGroup<T>;
const ownershipRequirements = assetConditionGroup as OwnershipRequirements<T>;

const depthLetter = String.fromCharCode(65 + depth);
const nextDepthLetter = String.fromCharCode(65 + depth + 1);
message += ' '.repeat(depth * 2) + `- Requirement ${depthLetter}${parentBullet}-${bulletNumber}`;
message += ' '.repeat(depth * 2) + `- Requirement ${depth == 0 ? '' : `${parentBullet ? parentBullet + '.' : ''}${bulletNumber}`}`;
if (andItem['$and'] !== undefined) {
message += ` (satisfied if all of ${nextDepthLetter}${bulletNumber} are satisfied):\n`;
message += ` (must satisfy all in group ${depth == 0 ? '' : `${parentBullet ? parentBullet + '.' : ''}${bulletNumber}`}):\n`;
for (let i = 0; i < andItem['$and'].length; i++) {
message += generateAssetConditionGroupString(andItem['$and'][i], depth + 1, i + 1, bulletNumber);
message += generateAssetConditionGroupString(andItem['$and'][i], depth + 1, i + 1, depth == 0 ? '' : `${parentBullet ? parentBullet + '.' : ''}${bulletNumber}`);
}
} else if (orItem['$or'] !== undefined) {
message += ` (satisfied if one of ${nextDepthLetter}${bulletNumber} is satisfied):\n`;
message += ` (must satisfy one in group ${depth == 0 ? '' : `${parentBullet ? parentBullet + '.' : ''}${bulletNumber}`}):\n`;
for (let i = 0; i < orItem['$or'].length; i++) {
message += generateAssetConditionGroupString(orItem['$or'][i], depth + 1, i + 1, bulletNumber);
message += generateAssetConditionGroupString(orItem['$or'][i], depth + 1, i + 1, depth == 0 ? '' : `${parentBullet ? parentBullet + '.' : ''}${bulletNumber}`);
}
} else {

Expand Down Expand Up @@ -646,7 +644,7 @@ function constructChallengeStringFromChallengeObject<T extends NumberType>(chall

if (challenge.assetOwnershipRequirements) {
message += `\nAsset Ownership Requirements:\n`;
message += generateAssetConditionGroupString(challenge.assetOwnershipRequirements, 0, 1, 1);
message += generateAssetConditionGroupString(challenge.assetOwnershipRequirements, 0, 1, '');
}

return message;
Expand Down

0 comments on commit 234df16

Please sign in to comment.