Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exports.acceptCredential = async function(theirDid, encryptedMessage) {
let myDid = await indy.pairwise.getMyDid(theirDid);
let credential = await await indy.crypto.authDecrypt(myDid, encryptedMessage);
let credentialRequestMetadata;
let pendingCredentialRequests = indy.store.pendingCredentialRequests.getAll();
for(let pendingCredReq of pendingCredentialRequests) {
if(pendingCredReq.credRequestJson.cred_def_id === credential.cred_def_id) { // FIXME: Check for match
credentialRequestMetadata = pendingCredReq.credRequestMetadataJson;
}
}
let [, credentialDefinition] = await indy.issuer.getCredDef(await indy.pool.get(), await indy.did.getEndpointDid(), credential.cred_def_id);
await sdk.proverStoreCredential(await indy.wallet.get(), null, credentialRequestMetadata, credential, credentialDefinition);
let credentials = await indy.credentials.getAll();
console.log(credentials);
};
exports.sendSchema = async function(poolHandle, walletHandle, Did, schema) {
// schema = JSON.stringify(schema); // FIXME: Check JSON parsing
let schemaRequest = await indy.buildSchemaRequest(Did, schema);
await indy.signAndSubmitRequest(poolHandle, walletHandle, Did, schemaRequest)
};
exports.acceptRequest = async function (theirEndpointDid, theirDid, requestNonce) {
let [myDid, myVerkey] = await sdk.createAndStoreMyDid(await indy.wallet.get(), {});
let theirVerkey = await sdk.keyForDid(await indy.pool.get(), await indy.wallet.get(), theirDid);
// await sdk.storeTheirDid(await indy.wallet.get(), {
// did: theirDid,
// verkey: theirVerkey
// });
let meta = JSON.stringify({
theirEndpointDid: theirEndpointDid,
verified: false // Indicates that the owner of the agent has confirmed they want to stay connected with this person.
});
//FIXME: Check to see if pairwise exists
await sdk.createPairwise(await indy.wallet.get(), theirDid, myDid, meta);
// Send connections response
let connectionResponse = {
exports.sendRequest = async function (theirDid, encryptedMessage) {
let myDid = await indy.pairwise.getMyDid(theirDid);
let credentialOffer = await indy.crypto.authDecrypt(myDid, encryptedMessage);
let [, credentialDefinition] = await indy.issuer.getCredDef(await indy.pool.get(), await indy.did.getEndpointDid(), credentialOffer.cred_def_id); // FIXME: Was passing in myDid. Why?
let masterSecretId = await indy.did.getEndpointDidAttribute('master_secret_id');
let [credRequestJson, credRequestMetadataJson] = await sdk.proverCreateCredentialReq(await indy.wallet.get(), myDid, credentialOffer, credentialDefinition, masterSecretId);
indy.store.pendingCredentialRequests.write(credRequestJson, credRequestMetadataJson);
let message = await indy.crypto.buildAuthcryptedMessage(myDid, theirDid, MESSAGE_TYPES.REQUEST, credRequestJson);
let theirEndpointDid = await indy.did.getTheirEndpointDid(theirDid);
return indy.crypto.sendAnonCryptedMessage(theirEndpointDid, message);
};
let theirVerKey = message.verkey;
if (relationship.nonce !== message.nonce) {
throw Error("NoncesDontMatch");
} else {
await sdk.storeTheirDid(await indy.wallet.get(), {
did: theirDid,
verkey: theirVerKey
});
let meta = JSON.stringify({
name: relationship.name,
alias: relationship.alias,
theirEndpointDid: relationship.theirEndpointDid
});
await sdk.createPairwise(await indy.wallet.get(), theirDid, relationship.myNewDid, meta);
// send acknowledge
await exports.sendAcknowledgement(relationship.myNewDid, theirDid, relationship.theirEndpointDid);
indy.store.pendingRelationships.delete(relationship.id);
}
}
};
let [myDid, myVerkey] = await sdk.createAndStoreMyDid(await indy.wallet.get(), {});
let theirVerkey = await sdk.keyForDid(await indy.pool.get(), await indy.wallet.get(), theirDid);
// await sdk.storeTheirDid(await indy.wallet.get(), {
// did: theirDid,
// verkey: theirVerkey
// });
let meta = JSON.stringify({
theirEndpointDid: theirEndpointDid,
verified: false // Indicates that the owner of the agent has confirmed they want to stay connected with this person.
});
//FIXME: Check to see if pairwise exists
await sdk.createPairwise(await indy.wallet.get(), theirDid, myDid, meta);
// Send connections response
let connectionResponse = {
did: myDid,
verkey: myVerkey,
nonce: requestNonce
};
let message = {
aud: theirDid,
type: MESSAGE_TYPES.RESPONSE,
message: await indy.crypto.anonCrypt(theirDid, JSON.stringify(connectionResponse))
};
return indy.crypto.sendAnonCryptedMessage(theirEndpointDid, message);
};
exports.setup = async function () {
// see PlenumProtocolVersion or indy-plenum.common.constans.CURRENT_PROTOCOL_VERSION
await sdk.setProtocolVersion(2);
let poolGenesisTxnPath = await exports.getPoolGenesisTxnPath(config.poolName);
let poolConfig = {
"genesis_txn": poolGenesisTxnPath
};
try {
await sdk.createPoolLedgerConfig(config.poolName, poolConfig);
} catch (e) {
if (e.message !== "PoolLedgerConfigAlreadyExistsError") {
throw e;
}
} finally {
pool = await sdk.openPoolLedger(config.poolName);
}
};
exports.setup = async function () {
// see PlenumProtocolVersion or indy-plenum.common.constans.CURRENT_PROTOCOL_VERSION
await sdk.setProtocolVersion(2);
let poolGenesisTxnPath = await exports.getPoolGenesisTxnPath(config.poolName);
let poolConfig = {
"genesis_txn": poolGenesisTxnPath
};
try {
await sdk.createPoolLedgerConfig(config.poolName, poolConfig);
} catch (e) {
if (e.message !== "PoolLedgerConfigAlreadyExistsError") {
throw e;
}
} finally {
pool = await sdk.openPoolLedger(config.poolName);
}
};
throw e;
}
} finally {
console.info('wallet already exist, try to open wallet');
}
stewardWallet = await sdk.openWallet(
{id: stewardWalletName},
{key: 'whatever'}
);
let stewardDidInfo = {
'seed': '000000000000000000000000Steward1'
};
[stewardDid, stewardKey] = await sdk.createAndStoreMyDid(stewardWallet, stewardDidInfo);
}
exports.getVerinym = async function(poolHandle, From, fromWallet, fromDid, fromToKey, to, toWallet, toFromDid, toFromKey, role) {
console.log(`\"${to}\" > Create and store in Wallet \"${to}\" new DID"`);
let [toDid, toKey] = await indy.createAndStoreMyDid(toWallet, {});
console.log(`\"${to}\" > Authcrypt \"${to} DID info\" for \"${From}\"`);
let didInfoJson = JSON.stringify({
'did': toDid,
'verkey': toKey
});
let authcryptedDidInfo = await indy.cryptoAuthCrypt(toWallet, toFromKey, fromToKey, Buffer.from(didInfoJson, 'utf8'));
console.log(`\"${to}\" > Send authcrypted \"${to} DID info\" to ${From}`);
console.log(`\"${From}\" > Authdecrypted \"${to} DID info\" from ${to}`);
let [senderVerkey, authdecryptedDidInfo] =
await indy.cryptoAuthDecrypt(fromWallet, fromToKey, Buffer.from(authcryptedDidInfo));
let authdecryptedDidInfoJson = JSON.parse(Buffer.from(authdecryptedDidInfo));
console.log(`\"${From}\" > Authenticate ${to} by comparision of Verkeys`);