-1

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

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

3 回答 3

1

@法玛

你可以使用我下面的片段

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);
}
于 2019-10-31T12:17:31.543 回答
0

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 类文档

于 2022-01-01T08:21:35.223 回答