Skip to content

Commit

Permalink
Fix incorrect Condition parsing (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-roslaniec authored Jul 8, 2023
2 parents 61d30b6 + f85b3f8 commit ae56829
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 17 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@nucypher/nucypher-ts",
"author": "Piotr Roslaniec <p.roslaniec@gmail.com>",
"version": "1.0.0-beta.2",
"version": "1.0.0-beta.3",
"license": "GPL-3.0-only",
"repository": {
"type": "git",
Expand Down
8 changes: 2 additions & 6 deletions src/characters/porter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -138,18 +137,15 @@ export class Porter {
aliceVerifyingKey: PublicKey,
bobEncryptingKey: PublicKey,
bobVerifyingKey: PublicKey,
conditionsContext?: ConditionContext
conditionContextJSON?: string | undefined
): Promise<readonly RetrieveCFragsResult[]> {
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<PostRetrieveCFragsResponse> = await axios.post(
new URL('/retrieve_cfrags', this.porterUrl).toString(),
Expand Down
18 changes: 9 additions & 9 deletions src/characters/pre-recipient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<string, string>[], 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<string, string>) => {
return Condition.fromObj(ele);
});

const conditionContext = new ConditionContext(conditionsList, provider);
const conditionContext = new ConditionContext(conditions, provider);

const policyMessageKits = messageKits.map((mk) =>
PolicyMessageKit.fromMessageKit(
Expand All @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down

2 comments on commit ae56829

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bundled size for the package is listed below:

build/module/types/ethers-contracts/factories: 82.03 KB
build/module/types/ethers-contracts: 152.34 KB
build/module/types: 156.25 KB
build/module/src/policies: 19.53 KB
build/module/src/characters: 89.84 KB
build/module/src/agents: 35.16 KB
build/module/src/sdk/strategy: 31.25 KB
build/module/src/sdk: 46.88 KB
build/module/src/conditions/predefined: 19.53 KB
build/module/src/conditions/context: 42.97 KB
build/module/src/conditions/base: 54.69 KB
build/module/src/conditions: 156.25 KB
build/module/src/kits: 19.53 KB
build/module/src: 433.59 KB
build/module/test: 42.97 KB
build/module: 687.50 KB
build/main/types/ethers-contracts/factories: 82.03 KB
build/main/types/ethers-contracts: 152.34 KB
build/main/types: 156.25 KB
build/main/src/policies: 19.53 KB
build/main/src/characters: 89.84 KB
build/main/src/agents: 35.16 KB
build/main/src/sdk/strategy: 31.25 KB
build/main/src/sdk: 46.88 KB
build/main/src/conditions/predefined: 19.53 KB
build/main/src/conditions/context: 42.97 KB
build/main/src/conditions/base: 54.69 KB
build/main/src/conditions: 156.25 KB
build/main/src/kits: 19.53 KB
build/main/src: 437.50 KB
build/main/test: 46.88 KB
build/main: 695.31 KB
build: 1.35 MB

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bundled size for the package is listed below:

build/module/src/kits: 19.53 KB
build/module/src/characters: 89.84 KB
build/module/src/policies: 19.53 KB
build/module/src/agents: 35.16 KB
build/module/src/conditions/predefined: 19.53 KB
build/module/src/conditions/base: 54.69 KB
build/module/src/conditions/context: 42.97 KB
build/module/src/conditions: 156.25 KB
build/module/src/sdk/strategy: 31.25 KB
build/module/src/sdk: 46.88 KB
build/module/src: 433.59 KB
build/module/types/ethers-contracts/factories: 82.03 KB
build/module/types/ethers-contracts: 152.34 KB
build/module/types: 156.25 KB
build/module/test: 42.97 KB
build/module: 687.50 KB
build/main/src/kits: 19.53 KB
build/main/src/characters: 89.84 KB
build/main/src/policies: 19.53 KB
build/main/src/agents: 35.16 KB
build/main/src/conditions/predefined: 19.53 KB
build/main/src/conditions/base: 54.69 KB
build/main/src/conditions/context: 42.97 KB
build/main/src/conditions: 156.25 KB
build/main/src/sdk/strategy: 31.25 KB
build/main/src/sdk: 46.88 KB
build/main/src: 437.50 KB
build/main/types/ethers-contracts/factories: 82.03 KB
build/main/types/ethers-contracts: 152.34 KB
build/main/types: 156.25 KB
build/main/test: 46.88 KB
build/main: 695.31 KB
build: 1.35 MB

Please sign in to comment.