如何使用结构节点更新成员的从属关系和属性

How to update the affiliation and attribute of member using fabric node

我有 2 个组织和 2 个 fabric ca 的 fabric 网络设置,我已经注册并注册了用户。

 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.
  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

更新后重新注册:https://fabric-sdk-node.github.io/master/FabricCAClient.html#reenroll__anchor

@fama

你可以使用我下面的代码片段

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);
}
HLF 2.2

不再支持

client.setUserContext

如果您正在使用 HLF 2.2 并且需要列出从属关系,则可以使用以下代码段

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 })

有关其他方法的文档,请访问 AffiliationService Class documentation