From 298fe22e25674682ac04240957129af815ae56c8 Mon Sep 17 00:00:00 2001 From: Piotr Roslaniec Date: Fri, 7 Jul 2023 15:25:45 +0200 Subject: [PATCH 1/2] fix!: incorrect condition parsing leading to undefined variables in context --- src/characters/porter.ts | 8 ++------ src/characters/pre-recipient.ts | 18 +++++++++--------- test/utils.ts | 2 +- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/characters/porter.ts b/src/characters/porter.ts index 1bcc6aa41..2a3ef1d6a 100644 --- a/src/characters/porter.ts +++ b/src/characters/porter.ts @@ -9,7 +9,6 @@ import { import axios, { AxiosResponse } from 'axios'; import qs from 'qs'; -import { ConditionContext } from '../conditions'; import { Base64EncodedBytes, ChecksumAddress, HexEncodedBytes } from '../types'; import { fromBase64, fromHexString, toBase64, toHexString } from '../utils'; @@ -138,18 +137,15 @@ export class Porter { aliceVerifyingKey: PublicKey, bobEncryptingKey: PublicKey, bobVerifyingKey: PublicKey, - conditionsContext?: ConditionContext + conditionContextJSON?: string | undefined ): Promise { - const context = conditionsContext - ? await conditionsContext.toJson() - : undefined; const data: PostRetrieveCFragsRequest = { treasure_map: toBase64(treasureMap.toBytes()), retrieval_kits: retrievalKits.map((rk) => toBase64(rk.toBytes())), alice_verifying_key: toHexString(aliceVerifyingKey.toCompressedBytes()), bob_encrypting_key: toHexString(bobEncryptingKey.toCompressedBytes()), bob_verifying_key: toHexString(bobVerifyingKey.toCompressedBytes()), - context, + context: conditionContextJSON, }; const resp: AxiosResponse = await axios.post( new URL('/retrieve_cfrags', this.porterUrl).toString(), diff --git a/src/characters/pre-recipient.ts b/src/characters/pre-recipient.ts index ae0fc8cda..329d9c627 100644 --- a/src/characters/pre-recipient.ts +++ b/src/characters/pre-recipient.ts @@ -8,7 +8,7 @@ import { } from '@nucypher/nucypher-core'; import { ethers } from 'ethers'; -import { Condition, ConditionContext } from '../conditions'; +import { ConditionContext, ConditionExpression } from '../conditions'; import { Keyring } from '../keyring'; import { PolicyMessageKit } from '../kits/message'; import { RetrievalResult } from '../kits/retrieval'; @@ -103,14 +103,11 @@ export class PreTDecDecrypter { const conditions = messageKits .map((mk) => mk.conditions) .filter((condition): condition is Conditions => !!condition) - .map((condition) => JSON.parse(condition.toString())) - .reduce((acc: Record[], val) => acc.concat(val), []); + .map((condition) => ConditionExpression.fromJSON(condition.toString())) + .reduce((acc: ConditionExpression[], val) => acc.concat(val), []) + .map((condExpr: ConditionExpression) => condExpr.condition); - const conditionsList = conditions.map((ele: Record) => { - return Condition.fromObj(ele); - }); - - const conditionContext = new ConditionContext(conditionsList, provider); + const conditionContext = new ConditionContext(conditions, provider); const policyMessageKits = messageKits.map((mk) => PolicyMessageKit.fromMessageKit( @@ -121,13 +118,16 @@ export class PreTDecDecrypter { ); const retrievalKits = policyMessageKits.map((pk) => pk.asRetrievalKit()); + const conditionContextJSON = conditionContext + ? await conditionContext.toJson() + : undefined; const retrieveCFragsResponses = await this.porter.retrieveCFrags( treasureMap, retrievalKits, this.publisherVerifyingKey, this.decryptingKey, this.keyring.publicKey, - conditionContext + conditionContextJSON ); return zip(policyMessageKits, retrieveCFragsResponses).map((pair) => { diff --git a/test/utils.ts b/test/utils.ts index b79ca46d6..46dce7df5 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -82,7 +82,7 @@ export const fakeAlice = (aliceKey = 'fake-secret-key-32-bytes-alice-x') => { }; export const fakeWeb3Provider = ( - secretKeyBytes: Uint8Array, + secretKeyBytes = SecretKey.random().toBEBytes(), blockNumber?: number, blockTimestamp?: number ): ethers.providers.Web3Provider => { From f85b3f88e63203222c14cb1d559e19741fa03a6c Mon Sep 17 00:00:00 2001 From: Piotr Roslaniec Date: Fri, 7 Jul 2023 15:33:31 +0200 Subject: [PATCH 2/2] chore(release): 1.0.0-beta.3 --- CHANGELOG.md | 11 +++++++++++ package.json | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e6f194be..44270bfea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,17 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [1.0.0-beta.3](https://github.com/nucypher/nucypher-ts/compare/v1.0.0-beta.2...v1.0.0-beta.3) (2023-07-07) + + +### ⚠ BREAKING CHANGES + +* incorrect condition parsing leading to undefined variables in context + +### Bug Fixes + +* incorrect condition parsing leading to undefined variables in context ([298fe22](https://github.com/nucypher/nucypher-ts/commit/298fe22e25674682ac04240957129af815ae56c8)) + ## [1.0.0-beta.2](https://github.com/nucypher/nucypher-ts/compare/v1.0.0-alpha.0...v1.0.0-beta.2) (2023-07-07) ## [1.0.0-alpha.0](https://github.com/nucypher/nucypher-ts/compare/v1.0.0-beta.1...v1.0.0-alpha.0) (2023-06-27) diff --git a/package.json b/package.json index 025a952bc..f3d09820b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@nucypher/nucypher-ts", "author": "Piotr Roslaniec ", - "version": "1.0.0-beta.2", + "version": "1.0.0-beta.3", "license": "GPL-3.0-only", "repository": { "type": "git",