diff --git a/examples/pre/nextjs/src/app/page.tsx b/examples/pre/nextjs/src/app/page.tsx index 79648862b..5e612d6b6 100644 --- a/examples/pre/nextjs/src/app/page.tsx +++ b/examples/pre/nextjs/src/app/page.tsx @@ -2,6 +2,7 @@ import { Alice, Bob, + domains, EnactedPolicy, getPorterUri, initialize, @@ -106,7 +107,7 @@ function App() { const policy = await alice.grant( provider, provider.getSigner(), - getPorterUri('tapir'), // Testnet porter + getPorterUri(domains.TESTNET), policyParams, ); diff --git a/examples/pre/nodejs/src/index.ts b/examples/pre/nodejs/src/index.ts index 7cb42d360..931567605 100644 --- a/examples/pre/nodejs/src/index.ts +++ b/examples/pre/nodejs/src/index.ts @@ -1,6 +1,7 @@ import { Alice, Bob, + domains, getPorterUri, initialize, SecretKey, @@ -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...'); diff --git a/examples/pre/react/src/App.tsx b/examples/pre/react/src/App.tsx index d4901ad2b..54d9ea5a3 100644 --- a/examples/pre/react/src/App.tsx +++ b/examples/pre/react/src/App.tsx @@ -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'; @@ -48,8 +49,6 @@ function App() { return
Loading...
; } - console.log({ Alice, Bob, getPorterUri, SecretKey, toHexString }); - const makeAlice = () => { const alice = Alice.fromSecretKey(SecretKey.random()); setAlice(alice); @@ -96,11 +95,10 @@ function App() { startDate, endDate, }; - const policy = await alice.grant( provider, provider.getSigner(), - getPorterUri('tapir'), // Testnet porter + getPorterUri(domains.TESTNET), policyParams, ); diff --git a/examples/pre/webpack-5/src/index.ts b/examples/pre/webpack-5/src/index.ts index 3417a426d..fe05e1f4b 100644 --- a/examples/pre/webpack-5/src/index.ts +++ b/examples/pre/webpack-5/src/index.ts @@ -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 { @@ -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( diff --git a/examples/taco/nextjs/src/app/page.tsx b/examples/taco/nextjs/src/app/page.tsx index c9bcea875..adc7e6393 100644 --- a/examples/taco/nextjs/src/app/page.tsx +++ b/examples/taco/nextjs/src/app/page.tsx @@ -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'; @@ -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)); }; diff --git a/examples/taco/nodejs/src/index.ts b/examples/taco/nodejs/src/index.ts index be6f035ed..339fc7cb9 100644 --- a/examples/taco/nodejs/src/index.ts +++ b/examples/taco/nodejs/src/index.ts @@ -5,6 +5,7 @@ import { fromBytes, getPorterUri, initialize, + domains, toBytes, } from '@nucypher/taco'; import * as dotenv from 'dotenv'; @@ -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( diff --git a/examples/taco/react/src/App.tsx b/examples/taco/react/src/App.tsx index 4073fb53e..ad77f772a 100644 --- a/examples/taco/react/src/App.tsx +++ b/examples/taco/react/src/App.tsx @@ -1,6 +1,7 @@ import { conditions, decrypt, + domains, encrypt, fromBytes, getPorterUri, @@ -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)); }; diff --git a/examples/taco/webpack-5/src/index.ts b/examples/taco/webpack-5/src/index.ts index 370eada34..5b44889ab 100644 --- a/examples/taco/webpack-5/src/index.ts +++ b/examples/taco/webpack-5/src/index.ts @@ -5,6 +5,7 @@ import { fromBytes, getPorterUri, initialize, + domains, toBytes, } from '@nucypher/taco'; import { ethers } from 'ethers'; @@ -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); }; diff --git a/packages/pre/src/index.ts b/packages/pre/src/index.ts index 4f676b1ca..c5bf1e123 100644 --- a/packages/pre/src/index.ts +++ b/packages/pre/src/index.ts @@ -1,11 +1,3 @@ -export { - PorterClient, - fromHexString, - getPorterUri, - toBytes, - toHexString, -} from '@nucypher/shared'; - export { Ciphertext, EncryptedTreasureMap, @@ -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'; diff --git a/packages/shared/package.json b/packages/shared/package.json index bc61c6cac..9d5610b64 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -1,6 +1,6 @@ { "name": "@nucypher/shared", - "version": "0.1.0", + "version": "0.1.0-rc.1", "keywords": [ "pre", "taco", @@ -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", diff --git a/packages/shared/src/porter.ts b/packages/shared/src/porter.ts index 175355766..2de148620 100644 --- a/packages/shared/src/porter.ts +++ b/packages/shared/src/porter.ts @@ -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 = { +const porterUri: Record = { 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 = { + 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 diff --git a/packages/taco/package.json b/packages/taco/package.json index c5ee587ae..612325cd7 100644 --- a/packages/taco/package.json +++ b/packages/taco/package.json @@ -1,6 +1,6 @@ { "name": "@nucypher/taco", - "version": "0.1.0", + "version": "0.1.0-rc.2", "keywords": [ "taco", "threshold", @@ -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" }, diff --git a/packages/taco/src/index.ts b/packages/taco/src/index.ts index b1c36b574..f2d9646f4 100644 --- a/packages/taco/src/index.ts +++ b/packages/taco/src/index.ts @@ -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'; diff --git a/packages/taco/src/taco.ts b/packages/taco/src/taco.ts index 3a23bd132..317f1fb8e 100644 --- a/packages/taco/src/taco.ts +++ b/packages/taco/src/taco.ts @@ -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'; @@ -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 => { const ritualId = await DkgCoordinatorAgent.getRitualIdFromPublicKey( provider, diff --git a/packages/taco/test/taco.test.ts b/packages/taco/test/taco.test.ts index 6a62e1fdd..ba615f71a 100644 --- a/packages/taco/test/taco.test.ts +++ b/packages/taco/test/taco.test.ts @@ -81,8 +81,8 @@ describe('taco', () => { const decryptedMessage = await taco.decrypt( provider, messageKit, - signer, fakePorterUri, + signer, ); expect(getParticipantsSpy).toHaveBeenCalled(); expect(sessionKeySpy).toHaveBeenCalled(); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2e2c27101..4c2caa734 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -516,7 +516,7 @@ importers: specifier: 0.13.0-alpha.1 version: 0.13.0-alpha.1 '@nucypher/shared': - specifier: workspace:* + specifier: 0.1.0-rc.1 version: link:../shared ethers: specifier: ^5.7.2