HLF 1.4 中 HSMWalletMixin 的构造函数没有正确的变量

问题描述

我正在尝试使用 fabric-network V1.4.17 连接到 HSM,查看 HSMWalletMixin 构造函数,没有选项可以告诉类库标签和引脚。

相反,所有这些变量都可以在 X509WalletMixin 中找到。

这是类中的代码

export interface WalletMixin {} // tslint:disable-line:no-empty-interface

export class X509WalletMixin implements WalletMixin {
    public static createIdentity(mspId: string,certificate: string,privateKey: string): Identity;
    constructor(library?: string,slot?: string,pin?: string,userType?: string);
}

export class HSMWalletMixin implements WalletMixin {
    public static createIdentity(mspId: string,certificate: string): Identity;
    constructor();
}

所以我尝试使用 X509WalletMixin 创建一个 HSM 钱包,如下所示,但它创建了一个普通钱包。

const hsmWalletMixin = new X509WalletMixin('/path/to/lib/libCryptoki2_64.so','slot','pin');
const wallet = new FileSystemWallet(walletPath,hsmWalletMixin);

那么,如何创建 HSM 钱包呢?是否有一些环境变量,如本教程 Testing for Hardware Security Module via PKCS#11 中所述?

谢谢

解决方法

查看源代码实现是正确的 https://github.com/hyperledger/fabric-sdk-node/blob/4ca22aa1a70f464c3a5b9c259542aa7fee651061/fabric-network/lib/impl/wallet/hsmwalletmixin.js#L40

不正确的是类型定义,即您发布的代码片段。

只有在使用 typescript 时才会出现问题,在这种情况下,您只需要不使用 HSMWalletMixin 类型即可确保 typescript 不会尝试进行任何验证。