-1

I have fabric network setup with 2 organisation and 2 fabric ca, I have register and enrolled the user.

 1. How i can update the affiliation of user, I am trying to call the getCaName from node js and reenroll its doest not work.

 2. How to change the attribute of user using fabric node .

 3. How to revoke the certificate.
nagaraj
  • 797
  • 1
  • 6
  • 29

3 Answers3

1

@fama

you can use my below snippet

let adminUserObj = await client.setUserContext({
  username: admins.username,
  password: admins.secret
});

let caClient = client.getCertificateAuthority();

let affiliationService = caClient.newAffiliationService();
// Check if organization exists
let registeredAffiliations = await affiliationService.getAll(adminUserObj);
if (!registeredAffiliations.result.affiliations.some(x => x.name == userOrg.toLowerCase())) {
  let affiliation = userOrg.toLowerCase() + '.department1';
  await affiliationService.create({
    name: affiliation,
    force: true
  }, adminUserObj);
}
Narendranath Reddy
  • 3,833
  • 3
  • 13
  • 32
0
  1. https://fabric-sdk-node.github.io/IdentityService.html#update__anchor
  2. https://fabric-sdk-node.github.io/IdentityService.html#update__anchor
  3. https://fabric-sdk-node.github.io/master/FabricCAClient.html#revoke__anchor

Reenroll after the update: https://fabric-sdk-node.github.io/master/FabricCAClient.html#reenroll__anchor

kekomal
  • 2,179
  • 11
  • 12
  • do i need to use the chaincode to query this and update using above methods ? – nagaraj Oct 31 '19 at 10:40
  • That's a Node SDK client feature, not chaincode. A chaincode does not do this, it works in its channel context. Maybe you should stop and clarify Fabric concepts before continuing developing. There is a los of content online. – kekomal Oct 31 '19 at 10:46
  • You can also do it through fabric-ca-client command (https://hyperledger-fabric-ca.readthedocs.io/en/release-1.4/users-guide.html#fabric-ca-client), but you were already talking about NodeJS in your question. – kekomal Oct 31 '19 at 10:55
0

client.setUserContext is no longer supported by HLF 2.2

you can make use of below snippet if you are working with HLF 2.2 and need to list down affiliations

const { Wallets } = require('fabric-network');
const FabricCAServices = require('fabric-ca-client');
let connectionProfile = yaml.safeLoad(fs.readFileSync('../gateway/connection-org2.yaml', 'utf8'));
// Create a new CA client for interacting with the CA.
const caInfo = connectionProfile.certificateAuthorities['ca.org2.example.com'];
const caTLSCACerts = caInfo.tlsCACerts.pem;
const ca = new FabricCAServices(caInfo.url, { trustedRoots: caTLSCACerts, verify: false }, caInfo.caName);
const walletPath = path.join(process.cwd(), 'wallet');
const wallet = await Wallets.newFileSystemWallet(walletPath);
const provider = wallet.getProviderRegistry().getProvider(adminIdentity.type);
const adminUser = await provider.getUserContext(adminIdentity, 'admin');
let affiliationService = ca.newAffiliationService();
let registeredAffiliations = await affiliationService.getAll(adminUser);
console.dir(registeredAffiliations, { depth: null })

for documentation regarding other methods, visit AffiliationService Class documentation

alex devassy
  • 437
  • 5
  • 17