This repository has been archived by the owner on Feb 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 734
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from hyperledger/master
Pull from HL
- Loading branch information
Showing
74 changed files
with
4,192 additions
and
7,071 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
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
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
The file `ProofNegotiation.java` was moved from the obsolete | ||
directory `how-tos/proof-negotiation` and was renamed to | ||
`NegotiateProof.java` to be consistent with the scripts in | ||
other languages in the directory `negotiate-proof`. | ||
|
||
But this Java script was not tested or validated, and all the `java` | ||
directory must be completed (by a Java developper) (with `steps` and other) | ||
like for other "how-tos" scripts. |
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 |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# Negotiate a Proof | ||
|
||
Indy-SDK Developer Walkthrough #5, NodeJS Edition | ||
|
||
[ [Python](../python/README.md) | [Rust](../rust/README.md) | [Java](../../not-yet-written.md) | [.NET](../../not-yet-written.md) | [Objective C](../../not-yet-written.md) ] | ||
|
||
|
||
## Prerequisites | ||
|
||
Setup your workstation with an indy development virtual machine (VM). See [prerequisites](../../prerequisites.md). | ||
|
||
|
||
## Steps | ||
|
||
### Step 1 | ||
|
||
In your normal workstation operating system (not the VM), open a python editor of your | ||
choice and paste the code from [template.js](template.js) | ||
into a new doc. We will be modifying this code in later steps. | ||
|
||
Save the doc as `negotiateProof.js`. | ||
|
||
This is a very simple app framework into which you'll plug the code | ||
you'll be writing. | ||
|
||
### Step 2 | ||
|
||
This how-to builds on the work in ["Issue Credential"](../../issue-credential/README.md). | ||
Rather than duplicate our explanation of those steps here, we will simply | ||
copy that code as our starting point. | ||
|
||
Copy the contents of [step2.js](step2.js) into | ||
`negotiateProof.js` on top of the `Step 2 code goes here` placeholder comment. | ||
|
||
Save the updated version of `negotiateProof.js`. | ||
|
||
### Step 3 | ||
|
||
Proof negotiation typically begins when a *verifier* (also called a *relying party*) | ||
requests proof. (As with credential issuance, the process has three logical | ||
phases, but it is rare to begin with a proof offer. However, if an initial | ||
proof request is met with a counter-offer, the offering phase of the | ||
sequence becomes relevant.) | ||
|
||
![3 phases of proof negotiation; first phase is uncommon](../3-phases.png) | ||
|
||
A proof request is a JSON file that describes what sort of | ||
proof would satisfy the relying party. | ||
|
||
Once the proof request is received, a holder of credentials must scan their | ||
*identity wallet* to find out which credentials could be used to satisfy | ||
the request. (Wallet scanning is inefficient, but this does not cause | ||
problems for dozens or hundreds of credentials. At higher scale, a new | ||
mechanism is needed. | ||
[Work is underway](https://docs.google.com/presentation/d/1X6F9QVG8M4PqQQLLL_5I6aQ5z7CCpYyYHBNKYMlsqXc/edit#slide=id.g31e3a419cd_0_67) | ||
to add index-driven search to indy wallets. Visit | ||
[#indy-sdk on Rocket.Chat](https://chat.hyperledger.org/channel/indy-sdk) | ||
to learn more.) | ||
|
||
Copy the contents of [step3.js](step3.js) into | ||
`negotiateProof.js` on top of the `Step 3 code goes here` placeholder comment. | ||
|
||
Save the updated version of `negotiateProof.js`. | ||
|
||
### Step 4 | ||
|
||
At this point, the holder becomes a *prover* by generating and presenting | ||
a proof. This is done by building some JSON that selects the credentials | ||
(out of those identified as valid candidates in the previous step), | ||
that the prover wishes to use to satisfy the request. The prover calls | ||
`indy.proverCreateProof()` with appropriate parameters, and the | ||
proof is created. | ||
|
||
Copy the contents of [step4.js](step4.js) into | ||
`negotiateProof.js` on top of the `Step 4 code goes here` placeholder comment. | ||
|
||
Save the updated version of `negotiateProof.js`. | ||
|
||
### Step 6 | ||
|
||
Finally, the verifier needs to check to be sure the proof that's presented | ||
satisfies their criteria. This is easy; just call `indy.verifierVerifyProof()`. | ||
|
||
Copy the contents of [step5.js](step5.js) into | ||
`negotiateProof.js` on top of the `Step 5 code goes here` placeholder comment. | ||
|
||
Save the updated version of `negotiateProof.js`. | ||
|
||
### Step 6 | ||
|
||
Run the [finished code](negotiateProof.js) and observe the whole sequence. | ||
|
||
## More experiments | ||
|
||
You might try the ["Send a Secure Message"](../../send-secure-msg/../not-yet-written.md) | ||
how-to. |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// https://github.com/shiena/ansicolor/blob/master/README.md | ||
module.exports = { | ||
NONE: "\x1b[0m", | ||
RED: "\x1b[31;01m", | ||
GREEN: "\x1b[32;01m", | ||
YELLOW: "\x1b[33;01m", | ||
BLUE: "\x1b[34;01m", | ||
MAGENTA: "\x1b[35;01m", | ||
CYAN: "\x1b[36;01m" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,168 @@ | ||
/** | ||
* Example demonstrating Proof Verification. | ||
* | ||
* First Issuer creates Credential Definition for existing Schema. | ||
* After that, it issues a Credential to Prover (as in issue_credential.py example) | ||
* | ||
* Once Prover has successfully stored its Credential, it uses Proof Request that he | ||
* received, to get Credentials which satisfy the Proof Request from his wallet. | ||
* Prover uses the output to create Proof, using its Master Secret. | ||
* After that, Proof is verified against the Proof Request | ||
*/ | ||
|
||
const indy = require('indy-sdk') | ||
const util = require('./util') | ||
const colors = require('./colors') | ||
|
||
const log = console.log | ||
|
||
function logValue() { | ||
log(colors.CYAN, ...arguments, colors.NONE) | ||
} | ||
|
||
|
||
async function run() { | ||
|
||
const issuerDid = "NcYxiDXkpYi6ov5FcYDi1e" | ||
const proverDid = "VsKV7grR1BUE29mG2Fm2kX" | ||
|
||
log("Set protocol version 2 to work with Indy Node 1.4") | ||
await indy.setProtocolVersion(2) | ||
|
||
// Step 2 code goes here. | ||
// 1. | ||
log("1. Creates Issuer wallet and opens it to get handle.") | ||
const issuerWalletName = {"id": "issuer_wallet"} | ||
const issuerWalletCredentials = {"key": "issuer_wallet_key"} | ||
await indy.createWallet(issuerWalletName, issuerWalletCredentials) | ||
const issuerWalletHandle = await indy.openWallet(issuerWalletName, issuerWalletCredentials) | ||
|
||
// 2. | ||
log("2. Creates Prover wallet and opens it to get handle.") | ||
const proverWalletName = {"id": "prover_wallet"} | ||
const proverWalletCredentials = {"key": "prover_wallet_key"} | ||
await indy.createWallet(proverWalletName, proverWalletCredentials) | ||
const proverWalletHandle = await indy.openWallet(proverWalletName, proverWalletCredentials) | ||
|
||
// 3. | ||
log("3. Issuer creates credential definition for schema") | ||
const schemaId = "1" | ||
const schema = { | ||
"id": schemaId, | ||
"ver": "1.0", | ||
"name": "gvt", | ||
"version": "1.0", | ||
"attrNames": ["age", "sex", "height", "name"] | ||
} | ||
const [credDefId, credDef] = await indy.issuerCreateAndStoreCredentialDef(issuerWalletHandle, issuerDid, schema, "tag1", "CL", '{"support_revocation": false}') | ||
|
||
// 4. | ||
log("4. Prover creates Link Secret") | ||
const proverMasterSecret = await indy.proverCreateMasterSecret(proverWalletHandle, "link_secret") | ||
|
||
// 5. | ||
log("5. Issuer create Cred Offer") | ||
const credOffer = await indy.issuerCreateCredentialOffer(issuerWalletHandle, credDefId) | ||
|
||
// 6. | ||
log("6. Prover creates and stores Cred Request") | ||
const [credReq, credReqMetadata] = await indy.proverCreateCredentialReq(proverWalletHandle, proverDid, credOffer, | ||
credDef, proverMasterSecret) | ||
|
||
// 7. | ||
log("7. Issuer creates Credential for received Cred Request") | ||
const credValues = { | ||
"sex": {"raw": "male", "encoded": "5944657099558967239210949258394887428692050081607692519917050011144233115103"}, | ||
"name": {"raw": "Alex", "encoded": "1139481716457488690172217916278103335"}, | ||
"height": {"raw": "175", "encoded": "175"}, | ||
"age": {"raw": "28", "encoded": "28"} | ||
} | ||
const tailsWriterConfig = {'base_dir': util.getPathToIndyClientHome() + "/tails", 'uri_pattern': ''} | ||
const blobStorageReaderHandle = await indy.openBlobStorageReader('default', tailsWriterConfig) | ||
const [cred] = await indy.issuerCreateCredential(issuerWalletHandle, credOffer, credReq, credValues, undefined, blobStorageReaderHandle) | ||
|
||
// 8. | ||
log("8. Prover processes and stores received Credential") | ||
await indy.proverStoreCredential(proverWalletHandle, undefined, credReqMetadata, cred, credDef,undefined) | ||
|
||
// Step 3 code goes here. | ||
log("9. Prover gets Credentials for Proof Request") | ||
const proofRequest = { | ||
'nonce': '123432421212', | ||
'name': 'proof_req_1', | ||
'version': '0.1', | ||
'requested_attributes': { | ||
'attr1_referent': { | ||
'name': 'name', | ||
'restrictions': [{ | ||
'cred_def_id': credDefId | ||
/* | ||
'issuer_did': issuerDid, | ||
'schema_key': schemaKey | ||
*/ | ||
}] | ||
} | ||
}, | ||
'requested_predicates': { | ||
'predicate1_referent': { | ||
'name': 'age', | ||
'p_type': '>=', | ||
'p_value': 18, | ||
'restrictions': [{'issuer_did': issuerDid}] | ||
} | ||
} | ||
} | ||
const credsForProofRequest = await indy.proverGetCredentialsForProofReq(proverWalletHandle, proofRequest) | ||
|
||
// Step 4 code goes here. | ||
log("10. Prover creates Proof for Proof Request") | ||
const credForAttr1 = credsForProofRequest["attrs"]["attr1_referent"] | ||
const referent = credForAttr1[0].cred_info.referent | ||
const requestedCredentials = { | ||
"self_attested_attributes": {}, | ||
"requested_attributes": { | ||
"attr1_referent": { | ||
cred_id: referent, | ||
revealed: true | ||
} | ||
}, | ||
"requested_predicates": { | ||
"predicate1_referent": { | ||
cred_id: referent | ||
} | ||
} | ||
} | ||
const schemas = { | ||
[schemaId]: schema | ||
} | ||
const credentialDefs = { | ||
[credDefId]: credDef | ||
} | ||
const revocRegs = {} | ||
const revRegs = {} | ||
const proof = await indy.proverCreateProof(proverWalletHandle, proofRequest, requestedCredentials, proverMasterSecret, schemas, credentialDefs, revocRegs) | ||
|
||
// Step 5 code goes here. | ||
log("11. Verifier is verifying proof from Prover") | ||
const verified = await indy.verifierVerifyProof(proofRequest, proof, schemas, credentialDefs, revocRegs, revRegs) | ||
|
||
logValue("Proof :") | ||
logValue(". Name="+proof['requested_proof']['revealed_attrs']['attr1_referent']['raw']) | ||
logValue(". Verified="+verified) | ||
|
||
// 12 | ||
log("12. Closing both wallet_handles") | ||
await indy.closeWallet(issuerWalletHandle) | ||
await indy.closeWallet(proverWalletHandle) | ||
|
||
// 13 | ||
log("13. Deleting created wallet_handles") | ||
await indy.deleteWallet(proverWalletName, proverWalletCredentials) | ||
await indy.deleteWallet(issuerWalletName, issuerWalletCredentials) | ||
} | ||
|
||
try { | ||
run() | ||
} catch (e) { | ||
log("ERROR occured : e") | ||
} |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "samples", | ||
"version": "1.0.0", | ||
"private": true, | ||
"description": "Demonstrates using NodeJS wrapper for LibIndy through creating and retrieving DIDs", | ||
"main": "writeDidAndQueryVerkey.js", | ||
"scripts": { | ||
"start": "node writeDidAndQueryVerkey.js", | ||
"ledger:start": "cd ../../../../ && docker build -f ci/indy-pool.dockerfile -t indy_pool . && docker run --name indy_pool -itd -p 9701-9708:9701-9708 indy_pool", | ||
"ledger:stop": "docker stop indy_pool && docker rm indy_pool" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/hyperledger/indy-sdk.git" | ||
}, | ||
"contributors": [ | ||
{ | ||
"name": "Xavier NOPRE", | ||
"email": "xnopre@twinpeek.net" | ||
} | ||
], | ||
"license": "Apache-2.0", | ||
"bugs": { | ||
"url": "https://github.com/hyperledger/indy-sdk/issues" | ||
}, | ||
"homepage": "https://github.com/hyperledger/indy-sdk#readme", | ||
"dependencies": { | ||
"cryptiles": "^4.1.1", | ||
"home-dir": "^1.0.0", | ||
"indy-sdk": "file:../../../../wrappers/nodejs", | ||
"mkdirp": "^0.5.1" | ||
} | ||
} |
Oops, something went wrong.