-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a0f1379
commit 4c9dd00
Showing
8 changed files
with
2,095 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
"version": "0.1.0", | ||
"keywords": [ | ||
"pre", | ||
"taco", | ||
"threshold", | ||
"access control" | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.