Skip to content

Commit 23821f0

Browse files
committed
NodeJS Getting-Started guide
Signed-off-by: artem.ivanov <[email protected]>
1 parent 3b20ece commit 23821f0

File tree

5 files changed

+138
-6022
lines changed

5 files changed

+138
-6022
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
cargo-registry
22
target
33
build
4+
node_modules
45
.idea
56
*.iml
67
.venv

samples/nodejs/gettingStarted.js

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@ async function run() {
3030

3131
console.log("\"Sovrin Steward\" -> Create wallet");
3232
let stewardWalletName = 'sovrinStewardWallet';
33+
let stewardWalletCredentials = {'key': 'steward_key'}
3334
try {
34-
await indy.createWallet(poolName, stewardWalletName);
35+
await indy.createWallet(poolName, stewardWalletName, 'default', null, stewardWalletCredentials)
3536
} catch(e) {
3637
if(e.message !== "WalletAlreadyExistsError") {
3738
throw e;
3839
}
3940
}
4041

41-
let stewardWallet = await indy.openWallet(stewardWalletName);
42+
let stewardWallet = await indy.openWallet(stewardWalletName, null, stewardWalletCredentials);
4243

4344
console.log("\"Sovrin Steward\" -> Create and store in Wallet DID from seed");
4445
let stewardDidInfo = {
@@ -51,7 +52,9 @@ async function run() {
5152
console.log("== Getting Trust Anchor credentials - Government Onboarding ==");
5253
console.log("------------------------------");
5354

54-
let [governmentWallet, governmentWalletName, stewardGovernmentKey, governmentStewardDid, governmentStewardKey] = await onboarding(poolHandle, poolName, "Sovrin Steward", stewardWallet, stewardDid, "Government", null, 'governmentWallet');
55+
let governmentWalletName = 'governmentWallet'
56+
let governmentWalletCredentials = {'key': 'government_key'}
57+
let [governmentWallet, stewardGovernmentKey, governmentStewardDid, governmentStewardKey] = await onboarding(poolHandle, poolName, "Sovrin Steward", stewardWallet, stewardDid, "Government", null, governmentWalletName, governmentWalletCredentials);
5558

5659
console.log("==============================");
5760
console.log("== Getting Trust Anchor credentials - Government getting Verinym ==");
@@ -64,7 +67,10 @@ async function run() {
6467
console.log("==============================");
6568
console.log("== Getting Trust Anchor credentials - Faber Onboarding ==");
6669
console.log("------------------------------");
67-
let [faberWallet, faberWalletName, stewardFaberKey, faberStewardDid, faberStewardKey] = await onboarding(poolHandle, poolName, "Sovrin Steward", stewardWallet, stewardDid, "Faber", null, 'faberWallet');
70+
71+
let faberWalletName = 'faberWallet'
72+
let faberWalletCredentials = {'key': 'faber_key'}
73+
let [faberWallet, stewardFaberKey, faberStewardDid, faberStewardKey] = await onboarding(poolHandle, poolName, "Sovrin Steward", stewardWallet, stewardDid, "Faber", null, faberWalletName, faberWalletCredentials);
6874

6975
console.log("==============================");
7076
console.log("== Getting Trust Anchor credentials - Faber getting Verinym ==");
@@ -77,7 +83,9 @@ async function run() {
7783
console.log("== Getting Trust Anchor credentials - Acme Onboarding ==");
7884
console.log("------------------------------");
7985

80-
let [acmeWallet, acmeWalletName, stewardAcmeKey, acmeStewardDid, acmeStewardKey] = await onboarding(poolHandle, poolName, "Sovrin Steward", stewardWallet, stewardDid, "Acme", null, 'acmeWallet');
86+
let acmeWalletName = 'acmeWallet'
87+
let acmeWalletCredentials = {'key': 'acme_key'}
88+
let [acmeWallet, stewardAcmeKey, acmeStewardDid, acmeStewardKey] = await onboarding(poolHandle, poolName, "Sovrin Steward", stewardWallet, stewardDid, "Acme", null, acmeWalletName, acmeWalletCredentials);
8189

8290
console.log("==============================");
8391
console.log("== Getting Trust Anchor credentials - Acme getting Verinym ==");
@@ -90,7 +98,9 @@ async function run() {
9098
console.log("== Getting Trust Anchor credentials - Thrift Onboarding ==");
9199
console.log("------------------------------");
92100

93-
let [thriftWallet, thriftWalletName, stewardThriftKey, thriftStewardDid, thriftStewardKey] = await onboarding(poolHandle, poolName, "Sovrin Steward", stewardWallet, stewardDid, "Thrift", null, ' thriftWallet');
101+
let thriftWalletName = 'thriftWallet'
102+
let thriftWalletCredentials = {'key': 'thrift_key'}
103+
let [thriftWallet, stewardThriftKey, thriftStewardDid, thriftStewardKey] = await onboarding(poolHandle, poolName, "Sovrin Steward", stewardWallet, stewardDid, "Thrift", null, thriftWalletName, thriftWalletCredentials);
94104

95105
console.log("==============================");
96106
console.log("== Getting Trust Anchor credentials - Thrift getting Verinym ==");
@@ -150,7 +160,9 @@ async function run() {
150160
console.log("== Getting Transcript with Faber - Onboarding ==");
151161
console.log("------------------------------");
152162

153-
let [aliceWallet, aliceWalletName, faberAliceKey, aliceFaberDid, aliceFaberKey, faberAliceConnectionResponse] = await onboarding(poolHandle, poolName, "Faber", faberWallet, faberDid, "Alice", null, ' aliceWallet');
163+
let aliceWalletName = 'aliceWallet'
164+
let aliceWalletCredentials = {'key': 'alice_key'}
165+
let [aliceWallet, faberAliceKey, aliceFaberDid, aliceFaberKey, faberAliceConnectionResponse] = await onboarding(poolHandle, poolName, "Faber", faberWallet, faberDid, "Alice", null, aliceWalletName, aliceWalletCredentials);
154166

155167
console.log("==============================");
156168
console.log("== Getting Transcript with Faber - Getting Transcript Credential ==");
@@ -220,7 +232,8 @@ async function run() {
220232
console.log("== Apply for the job with Acme - Onboarding ==");
221233
console.log("------------------------------");
222234
let acmeAliceKey, aliceAcmeDid, aliceAcmeKey, acmeAliceConnectionResponse;
223-
[aliceWallet, aliceWalletName, acmeAliceKey, aliceAcmeDid, aliceAcmeKey, acmeAliceConnectionResponse] = await onboarding(poolHandle, poolName, "Acme", acmeWallet, acmeDid, "Alice", aliceWallet, ' aliceWallet');
235+
236+
[aliceWallet, acmeAliceKey, aliceAcmeDid, aliceAcmeKey, acmeAliceConnectionResponse] = await onboarding(poolHandle, poolName, "Acme", acmeWallet, acmeDid, "Alice", aliceWallet, aliceWalletName, aliceWalletCredentials);
224237

225238
console.log("==============================");
226239
console.log("== Apply for the job with Acme - Transcript proving ==");
@@ -402,8 +415,8 @@ async function run() {
402415
console.log("------------------------------");
403416

404417
let thriftAliceKey, aliceThriftDid, aliceThriftKey, thriftAliceConnectionResponse;
405-
[aliceWallet, aliceWalletName, thriftAliceKey, aliceThriftDid, aliceThriftKey, thriftAliceConnectionResponse] = await onboarding(poolHandle, poolName, "Thrift", thriftWallet, thriftDid,
406-
"Alice", aliceWallet, ' aliceWallet');
418+
[aliceWallet, thriftAliceKey, aliceThriftDid, aliceThriftKey, thriftAliceConnectionResponse] = await onboarding(poolHandle, poolName, "Thrift", thriftWallet, thriftDid,
419+
"Alice", aliceWallet, aliceWalletName, aliceWalletCredentials);
407420

408421
console.log("==============================");
409422
console.log("== Apply for the loan with Thrift - Job-Certificate proving ==");
@@ -583,27 +596,27 @@ async function run() {
583596

584597
console.log(" \"Sovrin Steward\" -> Close and Delete wallet");
585598
await indy.closeWallet(stewardWallet);
586-
await indy.deleteWallet(stewardWalletName, null);
599+
await indy.deleteWallet(stewardWalletName, stewardWalletCredentials);
587600

588601
console.log("\"Government\" -> Close and Delete wallet");
589602
await indy.closeWallet(governmentWallet);
590-
await indy.deleteWallet(governmentWalletName, null);
603+
await indy.deleteWallet(governmentWalletName, governmentWalletCredentials);
591604

592605
console.log("\"Faber\" -> Close and Delete wallet");
593606
await indy.closeWallet(faberWallet);
594-
await indy.deleteWallet(faberWalletName, null);
607+
await indy.deleteWallet(faberWalletName, faberWalletCredentials);
595608

596609
console.log("\"Acme\" -> Close and Delete wallet");
597610
await indy.closeWallet(acmeWallet);
598-
await indy.deleteWallet(acmeWalletName, null);
611+
await indy.deleteWallet(acmeWalletName, acmeWalletCredentials);
599612

600613
console.log("\"Thrift\" -> Close and Delete wallet");
601614
await indy.closeWallet(thriftWallet);
602-
await indy.deleteWallet(thriftWalletName, null);
615+
await indy.deleteWallet(thriftWalletName, thriftWalletCredentials);
603616

604617
console.log("\"Alice\" -> Close and Delete wallet");
605618
await indy.closeWallet(aliceWallet);
606-
await indy.deleteWallet(aliceWalletName, null);
619+
await indy.deleteWallet(aliceWalletName, aliceWalletCredentials);
607620

608621
console.log("Close and Delete pool");
609622
await indy.closePoolLedger(poolHandle);
@@ -612,7 +625,7 @@ async function run() {
612625
console.log("Getting started -> done")
613626
}
614627

615-
async function onboarding(poolHandle, poolName, From, fromWallet, fromDid, to, toWallet, toWalletName) {
628+
async function onboarding(poolHandle, poolName, From, fromWallet, fromDid, to, toWallet, toWalletName, toWalletCredentials) {
616629
console.log(`\"${From}\" > Create and store in Wallet \"${From} ${to}\" DID`);
617630
let [fromToDid, fromToKey] = await indy.createAndStoreMyDid(fromWallet, {});
618631

@@ -628,13 +641,13 @@ async function onboarding(poolHandle, poolName, From, fromWallet, fromDid, to, t
628641
if (!toWallet) {
629642
console.log(`\"${to}\" > Create wallet"`);
630643
try {
631-
await indy.createWallet(poolName, toWalletName);
644+
await indy.createWallet(poolName, toWalletName, 'default', null, toWalletCredentials)
632645
} catch(e) {
633646
if(e.message !== "WalletAlreadyExistsError") {
634647
throw e;
635648
}
636649
}
637-
toWallet = await indy.openWallet(toWalletName);
650+
toWallet = await indy.openWallet(toWalletName, null, toWalletCredentials);
638651
}
639652

640653
console.log(`\"${to}\" > Create and store in Wallet \"${to} ${From}\" DID`);
@@ -664,7 +677,7 @@ async function onboarding(poolHandle, poolName, From, fromWallet, fromDid, to, t
664677
console.log(`\"${From}\" > Send Nym to Ledger for \"${to} ${From}\" DID`);
665678
await sendNym(poolHandle, fromWallet, fromDid, decryptedConnectionResponse['did'], decryptedConnectionResponse['verkey'], null);
666679

667-
return [toWallet, toWalletName, fromToKey, toFromDid, toFromKey, decryptedConnectionResponse];
680+
return [toWallet, fromToKey, toFromDid, toFromKey, decryptedConnectionResponse];
668681
}
669682

670683
async function getVerinym(poolHandle, From, fromWallet, fromDid, fromToKey, to, toWallet, toFromDid, toFromKey, role) {

0 commit comments

Comments
 (0)