Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/pre/nextjs/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import {
Alice,
Bob,
domains,
EnactedPolicy,
getPorterUri,
initialize,
Expand Down Expand Up @@ -106,7 +107,7 @@ function App() {
const policy = await alice.grant(
provider,
provider.getSigner(),
getPorterUri('tapir'), // Testnet porter
getPorterUri(domains.TESTNET),
policyParams,
);

Expand Down
3 changes: 2 additions & 1 deletion examples/pre/nodejs/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
Alice,
Bob,
domains,
getPorterUri,
initialize,
SecretKey,
Expand Down Expand Up @@ -58,7 +59,7 @@ const runExample = async () => {
startDate: new Date(),
endDate: new Date(Date.now() + 1000 * 60 * 60 * 24 * 30), // In 30 days,
};
const porterUri = getPorterUri('tapir'); // Test network
const porterUri = getPorterUri(domains.TESTNET);
const alice = makeAlice();

console.log('Creating policy...');
Expand Down
8 changes: 3 additions & 5 deletions examples/pre/react/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {
Alice,
Bob,
domains,
EnactedPolicy,
getPorterUri,
initialize,
SecretKey,
toHexString,
toHexString
} from '@nucypher/pre';
import { ethers } from 'ethers';
import { useEffect, useState } from 'react';
Expand Down Expand Up @@ -48,8 +49,6 @@ function App() {
return <div>Loading...</div>;
}

console.log({ Alice, Bob, getPorterUri, SecretKey, toHexString });

const makeAlice = () => {
const alice = Alice.fromSecretKey(SecretKey.random());
setAlice(alice);
Expand Down Expand Up @@ -96,11 +95,10 @@ function App() {
startDate,
endDate,
};

const policy = await alice.grant(
provider,
provider.getSigner(),
getPorterUri('tapir'), // Testnet porter
getPorterUri(domains.TESTNET),
policyParams,
);

Expand Down
11 changes: 9 additions & 2 deletions examples/pre/webpack-5/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { Alice, Bob, SecretKey, getPorterUri, initialize } from '@nucypher/pre';
import {
Alice,
Bob,
domains,
getPorterUri,
initialize,
SecretKey,
} from '@nucypher/pre';
import { ethers } from 'ethers';

declare global {
Expand Down Expand Up @@ -58,7 +65,7 @@ const runExample = async () => {
startDate,
endDate,
};
const porterUri = getPorterUri('tapir'); // Test network
const porterUri = getPorterUri(domains.TESTNET);

const alice = makeAlice();
const policy = await alice.grant(
Expand Down
10 changes: 6 additions & 4 deletions examples/taco/nextjs/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
import {
conditions,
decrypt,
encrypt, fromBytes,
domains,
encrypt,
fromBytes,
getPorterUri,
initialize,
initialize
} from '@nucypher/taco';
import {ethers} from 'ethers';
import {useEffect, useState} from 'react';
Expand Down Expand Up @@ -89,8 +91,8 @@ function App() {
const messageKit = await encrypt(provider, message, hasPositiveBalance, ritualId, signer);

console.log('Decrypting message...');
const porterUri = getPorterUri('lynx'); // Test network
const decryptedMessage = await decrypt(provider, messageKit, signer, porterUri);
const porterUri = getPorterUri(domains.DEV);
const decryptedMessage = await decrypt(provider, messageKit,porterUri,signer);

setDecryptedMessage(fromBytes(decryptedMessage));
};
Expand Down
5 changes: 3 additions & 2 deletions examples/taco/nodejs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
fromBytes,
getPorterUri,
initialize,
domains,
toBytes,
} from '@nucypher/taco';
import * as dotenv from 'dotenv';
Expand Down Expand Up @@ -57,8 +58,8 @@ const runExample = async () => {
);

console.log('Decrypting message...');
const porterUri = getPorterUri('lynx'); // Test network
const decryptedBytes = await decrypt(provider, messageKit, signer, porterUri);
const porterUri = getPorterUri(domains.DEV);
const decryptedBytes = await decrypt(provider, messageKit, porterUri, signer);
const decryptedMessageString = fromBytes(decryptedBytes);
console.log('Decrypted message:', decryptedMessageString);
console.assert(
Expand Down
5 changes: 3 additions & 2 deletions examples/taco/react/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
conditions,
decrypt,
domains,
encrypt,
fromBytes,
getPorterUri,
Expand Down Expand Up @@ -89,8 +90,8 @@ function App() {
const messageKit = await encrypt(provider, message, hasPositiveBalance, ritualId, signer);

console.log('Decrypting message...');
const porterUri = getPorterUri('lynx'); // Test network
const decryptedMessage = await decrypt(provider, messageKit, signer, porterUri);
const porterUri = getPorterUri(domains.DEV);
const decryptedMessage = await decrypt(provider, messageKit, porterUri, signer);

setDecryptedMessage(fromBytes(decryptedMessage));
};
Expand Down
5 changes: 3 additions & 2 deletions examples/taco/webpack-5/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
fromBytes,
getPorterUri,
initialize,
domains,
toBytes,
} from '@nucypher/taco';
import { ethers } from 'ethers';
Expand Down Expand Up @@ -47,8 +48,8 @@ const runExample = async () => {
);

console.log('Decrypting message...');
const porterUri = getPorterUri('lynx'); // Test network
const decryptedBytes = await decrypt(provider, messageKit, signer, porterUri);
const porterUri = getPorterUri(domains.DEV);
const decryptedBytes = await decrypt(provider, messageKit, porterUri, signer);
const decryptedMessage = fromBytes(decryptedBytes);
console.log('Decrypted message:', decryptedMessage);
};
Expand Down
10 changes: 1 addition & 9 deletions packages/pre/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
export {
PorterClient,
fromHexString,
getPorterUri,
toBytes,
toHexString,
} from '@nucypher/shared';

export {
Ciphertext,
EncryptedTreasureMap,
Expand All @@ -15,8 +7,8 @@ export {
SecretKey,
Signer,
TreasureMap,
initialize,
} from '@nucypher/nucypher-core';
export { fromBytes, initialize, toBytes, toHexString, getPorterUri, domains } from '@nucypher/shared';

export { Alice, Bob, Enrico } from './characters';
export { Cohort } from './cohort';
Expand Down
3 changes: 1 addition & 2 deletions packages/shared/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nucypher/shared",
"version": "0.1.0",
"version": "0.1.0-rc.1",
"keywords": [
"pre",
"taco",
Expand Down Expand Up @@ -32,7 +32,6 @@
"build:module": "tsc --build ./tsconfig.es.json --verbose",
"clean": "rm -rf dist",
"exports:lint": "ts-unused-exports tsconfig.json --ignoreFiles src/index.ts",
"postinstall": "pnpm typechain",
"lint": "eslint --ext .ts src",
"lint:fix": "pnpm lint --fix",
"package-check": "package-check",
Expand Down
20 changes: 13 additions & 7 deletions packages/shared/src/porter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,27 @@ import qs from 'qs';
import { Base64EncodedBytes, ChecksumAddress, HexEncodedBytes } from './types';
import { fromBase64, fromHexString, toBase64, toHexString } from './utils';

type Network = 'mainnet' | 'tapir' | 'oryx' | 'lynx';

const PORTER_URIS: Record<Network, string> = {
const porterUri: Record<string, string> = {
mainnet: 'https://porter.nucypher.community',
tapir: 'https://porter-tapir.nucypher.community',
oryx: 'https://porter-oryx.nucypher.community',
lynx: 'https://porter-lynx.nucypher.community',
};

export const getPorterUri = (network: Network): string => {
const uri = PORTER_URIS[network];
export type Domain = keyof typeof porterUri;

export const domains: Record<string, Domain> = {
DEV: 'lynx',
TESTNET: 'tapir',
MAINNET: 'mainnet',
};

export const getPorterUri = (domain: Domain): string => {
const uri = porterUri[domain];
if (!uri) {
throw new Error(`No default Porter URI found for network: ${network}`);
throw new Error(`No default Porter URI found for domain: ${domain}`);
}
return PORTER_URIS[network];
return porterUri[domain];
};

// /get_ursulas
Expand Down
4 changes: 2 additions & 2 deletions packages/taco/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nucypher/taco",
"version": "0.1.0",
"version": "0.1.0-rc.2",
"keywords": [
"taco",
"threshold",
Expand Down Expand Up @@ -40,7 +40,7 @@
"dependencies": {
"@ethersproject/abstract-signer": "^5.7.0",
"@nucypher/nucypher-core": "0.13.0-alpha.1",
"@nucypher/shared": "workspace:*",
"@nucypher/shared": "0.1.0-rc.1",
"semver": "^7.5.2",
"zod": "^3.22.1"
},
Expand Down
6 changes: 2 additions & 4 deletions packages/taco/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
export { DkgPublicKey, ThresholdMessageKit } from '@nucypher/nucypher-core';

export { fromBytes, getPorterUri, initialize, toBytes } from '@nucypher/shared';
export { fromBytes, initialize, toBytes, toHexString, getPorterUri, domains } from '@nucypher/shared';

export * as conditions from './conditions';

export { decrypt, encrypt } from './taco';
export * from './taco';
9 changes: 2 additions & 7 deletions packages/taco/src/taco.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ import {
encryptForDkg,
ThresholdMessageKit,
} from '@nucypher/nucypher-core';
import {
DkgCoordinatorAgent,
fromHexString,
getPorterUri,
toBytes,
} from '@nucypher/shared';
import { DkgCoordinatorAgent, fromHexString, toBytes } from '@nucypher/shared';
import { ethers } from 'ethers';
import { keccak256 } from 'ethers/lib/utils';

Expand Down Expand Up @@ -77,8 +72,8 @@ export const encryptWithPublicKey = async (
export const decrypt = async (
provider: ethers.providers.Provider,
messageKit: ThresholdMessageKit,
porterUri: string,
signer?: ethers.Signer,
porterUri = getPorterUri('tapir'),
): Promise<Uint8Array> => {
const ritualId = await DkgCoordinatorAgent.getRitualIdFromPublicKey(
provider,
Expand Down
2 changes: 1 addition & 1 deletion packages/taco/test/taco.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ describe('taco', () => {
const decryptedMessage = await taco.decrypt(
provider,
messageKit,
signer,
fakePorterUri,
signer,
);
expect(getParticipantsSpy).toHaveBeenCalled();
expect(sessionKeySpy).toHaveBeenCalled();
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.