Skip to content

Commit

Permalink
apply pr suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-roslaniec committed Sep 15, 2023
1 parent a0f1379 commit 4c9dd00
Show file tree
Hide file tree
Showing 8 changed files with 2,095 additions and 5 deletions.
3 changes: 2 additions & 1 deletion examples/nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"type-check": "tsc -p tsconfig.build.json"
},
"dependencies": {
"@nucypher/shared": "workspace:*"
"@nucypher/shared": "workspace:*",
"ethers": "^5.7.2"
}
}
66 changes: 63 additions & 3 deletions examples/nodejs/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,64 @@
import { Cohort, getPorterUri } from '@nucypher/shared';
import {Alice, Bob, getPorterUri, SecretKey, toBytes} from '@nucypher/shared';
import { ethers } from 'ethers';

const myCohort = Cohort.create(getPorterUri('tapir'), 4);
console.log(myCohort);
const makeAlice = () => {
const secretKey = SecretKey.fromBEBytes(
toBytes('fake-secret-key-32-bytes-alice-x'),
);
return Alice.fromSecretKey(secretKey);
};

const makeBob = () => {
const secretKey = SecretKey.fromBEBytes(
toBytes('fake-secret-key-32-bytes-bob-xxx'),
);
return Bob.fromSecretKey(secretKey);
};

const makeRemoteBob = () => {
// The difference between a "Bob" and a "remote Bob" is that we only have
// access to public parameters in the latter, whereas in the former
// we also have access to Bob's secret key
const { decryptingKey, verifyingKey } = makeBob();
return { decryptingKey, verifyingKey };
};

const getRandomLabel = () => `label-${new Date().getTime()}`;

const runExample = async () => {
const provider = ethers.Wallet.createRandom();

const remoteBob = makeRemoteBob();
const threshold = 2;
const shares = 3;
const startDate = new Date();
const endDate = new Date(Date.now() + 1000 * 60 * 60 * 24 * 30); // In 30 days
const policyParams = {
bob: remoteBob,
label: getRandomLabel(),
threshold,
shares,
startDate,
endDate,
};
const porterUri = getPorterUri('tapir'); // Test network

const alice = makeAlice();
const policy = await alice.grant(
provider.provider,
provider,
porterUri,
policyParams,
);

console.log('Policy created:');
console.log({ policy });
};

runExample()
.then(() => {
console.log('Example finished.');
})
.catch((err) => {
console.error('Example failed:', err);
});
675 changes: 675 additions & 0 deletions packages/pre/LICENSE

Large diffs are not rendered by default.

675 changes: 675 additions & 0 deletions packages/shared/LICENSE

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.1.0",
"keywords": [
"pre",
"taco",
"threshold",
"access control"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/taco/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@nucypher/taco",
"version": "0.1.0",
"keywords": [
"pre",
"taco",
"threshold",
"access control"
],
Expand Down
Loading

0 comments on commit 4c9dd00

Please sign in to comment.